math

Newell's Method to Calculate Plane Equation of Concave Polygon - Improvements?

3 points are needed to define a plane. Newell's method is known to fail if the 3 points are chosen around a concave corner - the normal of the resulting plane will point in the direction opposite to the expected one. Are there any improvements to Newell's method that help in choosing a valid starting point? Or is there an alternative ...

Homework: Triangle angle calculation all sides known

I know I should do my homework on my own but I simply cant get my homework to work the way I want it to: from __future__ import division import turtle import math def triangle(c,a,b,beta,gamma): turtle.forward(c) turtle.right(180+beta) turtle.forward(a) turtle.right(beta) turtle.left(beta+gamma) turtle.forward(b...

Cubic root of the negative number on python.

Can someone help me to find solution on how to calculate cubic root of the negative number using python? >>> math.pow(-3, float(1)/3) nan it does not work. Cubic root of the negative number is negative number. Any solutions? ...

Programming a smooth change of thrust from current velocity vector to a target vector.

TL;dr: "I am not sure how to calculate a smooth transition of thrust between one vector and another." I am programming a simple game where an enemy chases after the player in an open space (no walls). I was calculating the enemy's x & y velocities independently, accelerating them if they were taking them in the direction of the player a...

C# to the power off help with calculation

hi there, Im not that great with maths and C# doesent seem to provide a power of function so i was wondering if anyone knows how i would run a calculation like this: var dimensions = ((100*100) / (100.00^3.00)); any help would be much appreciated thanks ...

How do I find a dimension of aspect ratio 4:3 which fits within a predetermined size?

The problem here is I have a display window of size x by y, and I need to display an image inside the window without any scrolling, and to maintain the aspect ratio of 4:3. I have the following snippet of code: // Lock the current height, calculate new width of the canvas and scale the viewport. // get width of the movie canvas qreal wi...

Generate random numbers distributed by Zipf

The Zipf probability distribution is often used to model file size distribution or item access distributions on items in P2P systems. e.g. "Web Caching and Zip like Distribution Evidence and Implications", but neither Boost or the GSL (Gnu Scientific Library) provide an implementation to generate random numbers using this distribution. I...

How can I optimize these queries?

Consider the following code snippet: $beat = date('B'); // 1 beat = 86.4 seconds, 1000 beats = 1 day $total = 'SELECT COUNT(id) FROM ads WHERE featured = 1;'; // number of featured ads $current = 'SELECT * FROM ads WHERE featured = 1 ORDER BY id ASC LIMIT 1 OFFSET ' . ($beat % $total) . ';'; // current featured ad Basically this cycl...

What is this piece of Python code doing?

This following is a snippet of Python code I found that solves a mathematical problem. What exactly is it doing? I wasn't too sure what to Google for. x, y = x + 3 * y, 4 * x + 1 * y Is this a special Python syntax? ...

Flipping an angle horizontally

I want to know a way to flip an angle in a horizontal axis, without having to do many operations. Say I have an angle of 0 ("pointing right" in my code's coordinate system), the flipped angle should be 180 (pointing left). If 90 (pointing up), flipped it should still be 90. 89 is 91, and so on. I can operate on the X/Y speeds implied by ...

two sets of 3d points

Hi everybody, I´ve got a question concerning two sets of points in a 3d space. I defined a volume by 40 coordinates in one cartesian coordinate system, in another coordinate system with different (0,0,0) i have s slightly different volume also defined by 40 coordinates. I know the matching pairs of the point sets and I want to measure t...

How do I create an identity matrix of arbitrary size in Java?

Is there a utility to create an identity matrix of specified size in Java? ...

Get New Co-Ordinate based on degrees and distance

I have a coordinate from Core Location and want to calculate the co-ordinate given a bearing and a distance, say in km. I think this is the formula from here. http://www.movable-type.co.uk/scripts/latlong.html Formula: lat2 = asin(sin(lat1)cos(d/R) + cos(lat1)sin(d/R)cos(θ)) lon2 = lon1 + atan2(sin(θ)sin(d/R)cos(lat1), ...

Mathematically Find Max Value without Conditional Comparison

----------Updated ------------ codymanix and moonshadow have been a big help thus far. I was able to solve my problem using the equations and instead of using right shift I divided by 29. Because with 32bits signed 2^31 = overflows to 29. Which works! Prototype in PHP $r = $x - (($x - $y) & (($x - $y) / (29))); Actual code for LEADS...

How to calculate an arbitrary power/root?

I have a application which needs to raise a number to a fractional power. The target platform is an FPGA and I can get estimates on an FPU size for it, but I need an algorithm for raising a number to a fractional power just for a feasibility study. I'm assuming floating point as a worst case, I expect in practice we will be able to use...

Finding area of straight line with graph (Math question but needed for flot)

Okay, so this is a straight math question and I read up on meta that those need to be written to sound like programming questions. I'll do my best... So I have graph made in flot that shows the network usage (in bytes/sec) for the user. The data is 4 minutes apart when there is activity, and otherwise set at the start of the usage range...

Optimizing points distance to sphere test.

I would like to test if a point is within a particular distance of a sphere. So you have these variables... Point3F spherePnt; F32 sphereRadius; Point3F testPnt; I could do... F32 dist = ( spherePnt - testPnt ).len() - sphereRadius; If dist is positive it is outside the radius, if dist is negative it is inside the radius. Or as a...

Can someone explain how Big-Oh works with Summations?

I know this isn't strictly a programming question, but it is a computer science question so I'm hoping someone can help me. I've been working on my Algorithms homework and figuring out the Big-Oh, Big-Omega, Theta, etc, of several algorithms. I'm proving them by finding their C and N0 values and all is going well. However, I've come a...

Why is squaring a number faster than multiplying two random numbers?

Multiplying two binary numbers takes n^2 time, yet squaring a number can be done more efficiently somehow. (with n being the number of bits) How could that be? Or is it not possible? This is insanity! ...

create mathmatical expression mfc (VS6)

Hello, I need to write some mathmatical expressions (like a matrix and mathematical variables...) into my GUI. The MFC static control is very limited on this issue. Especially for the math. symbols. is there any control or other way to make this happen? greetz Ric ...