trigonometry

get rotation direction of UIView on touchesMoved

this may sound funny, but i spent hours trying to recreate a knob with a realistic rotation using UIView and some trig. I achieved the goal, but now i can not figure out how to know if the knob is rotating left or right. The most pertinent part of the math is here: - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { ...

Is trigonometry computationally expensive?

I read in an article somewhere that trig calculations are generally expensive. Is this true? And if so, that's why they use trig-lookup tables right? EDIT: Hmm, so if the only thing that changes is the degrees (accurate to 1 degree), would a look up table with 360 entries (for every angle) be faster? ...

Drawing elements on an MKMapView of a specified size in meters

I'm attempting to draw a circle around a point on a mapview, which I have successfully done, but not quite the way I wanted to. The CG methods are always going to be drawing relative to the screen size, and basically I want to draw things in meters, not pixels. Anyone have experience doing this? ...

Calculating rotation in > 360 deg. situations

I'm trying to work out a problem I'm having with degrees. I have data that is a list of of angles, in standard degree notation -- e.g. 26 deg. Usually when dealing with angles, if an angle exceeds 360 deg then the angle continues around and effectively "resets" -- i.e. the angle "starts again", e.g. 357 deg, 358 deg, 359 deg, 0 deg, 1 ...

3D coordinate of 2D point given camera and view plane

I wish to generate rays from the camera through the viewing plane. In order to do this, I need my camera position ("eye"), the up, right, and towards vectors (where towards is the vector from the camera in the direction of the object that the camera is looking at) and P, the point on the viewing plane. Once I have these, the ray that's g...

Help Understanding Function

What does the following function perform? public static double CleanAngle(double angle) { while (angle < 0) angle += 2 * System.Math.PI; while (angle > 2 * System.Math.PI) angle -= 2 * System.Math.PI; return angle; } This is how it is used with ATan2. I believe the actually va...

calculating the potential effect of inaccurate triangle vertex positions on the triangle edge lenghts

i'm not sure how to solve the following problem: i have a triangle with each of the three known vertex positions A,B,C being inaccurate, meaning they can each deviate up to certain known radii rA, rB, rC into arbitrary directions. given such a triangle, i want to calculate how much the difference of two specific edge lengths (for insta...

Perturb vector by some angle

Hello: I have a unit vector in 3D space whose direction I wish to perturb by some angle within the range 0 to theta, with the position of the vector remaining the same. What is a way I can accomplish this? Thanks. EDIT: After thinking about the way I posed the question, it seems to be a bit too general. I'll attempt to make it more sp...

Angle between two 2d vectors, diff between two methods?

Hey all. I've got this code snippet, and I'm wondering why the results of the first method differ from the results of the second method, given the same input? public double AngleBetween_1(vector a, vector b) { var dotProd = a.Dot(b); var lenProd = a.Len*b.Len; var divOperation = dotProd/lenProd; return Math.Acos(divOperation) *...

How to interpret situations where Math.Acos() reports invalid input?

Hey all. I'm computing the angle between two vectors, and sometimes Math.Acos() returns NaN when it's input is out of bounds (-1 > input && input > 1) for a cosine. What does that mean, exactly? Would someone be able to explain what's happening? Any help is appreciated! Here's my method: public double AngleBetween(vector b) { ...

How can I work around the fact that in C++, sin(M_PI) is not 0?

In C++, const double Pi = 3.14159265; cout << sin(Pi); // displays: 3.58979e-009 it SHOULD display the number zero I understand this is because Pi is being approximated, but is there any way I can have a value of Pi hardcoded into my program that will return 0 for sin(Pi)? (a different constant maybe?) In c...

uniform generation of points on 3D box

Hello: I would like to generate random points on a 3D box defined by its (minx, miny, minz) and (maxx, maxy, maxz) corners. I was thinking of generating a random point inside of the box and then somehow projecting it onto one of the box sides. However, I don't have explicit plane information for the box sides and this seems like it will...

uniform generation of 3D points on cylinder/cone

Hello: I wish to randomly and uniformly generate points on a cylinder and a cone (separately). The cylinder is defined by its center, its radius and height. Same specifications for the cone. I am able to get the bounding box for each shape so I was thinking of generating points within the bounding box. However, I'm not sure how to proje...

How do i render and detect a line of sight?

If you look at the top right you'll see on a radar an enemy unit line of sight. I was wondering what is the most efficient or easiest way (little code, fairly accurate. doesnt need to be perfect) to detect if something is in your line of sight? I may or may not need to render it (i likely wont). I dont know the formula nor used any mat...

Built in raytracing?

Relating to this question i was wondering if .NET has any libs (or a function) i can use to detect if one point collides with another. I am not sure what angles i should use but is there some function like this func(point src, rect target, angle, distanceOfVision, listPointOrRectOfWalls) Pretty unlikely but i dont know a formula or h...

Difficulty with projectile's tracking code

I wrote some code for a projectile class in my game that makes it track targets if it can: if (_target != null && !_target.IsDead) { Vector2 currentDirectionVector = this.Body.LinearVelocity; currentDirectionVector.Normalize(); float currentDirection = (float)Math.A...

How to find coordinates of a 2d equilateral triangle in C ?

Hello, I have the coordinates (x,y) of 2 points. I want to build the third point so that these 3 points make an equilateral triangle. How can I calculate the third point? Thank you ...

Choosing circle radius to fully fill a rectangle

Hi, the pixman image library can draw radial color gradients between two circles. I'd like the radial gradient to fill a rectangular area defined by "width" and "height" completely. Now my question, how should I choose the radius of the outer circle? My current parameters are the following: A) inner circle (start of gradient) center p...

Good .NET library for fast streaming / batching trigonometry (Atan)?

I need to call Atan on millions of values per second. Is there a good library to perform this operation in batch very fast. For example, a library that streams the low level logic using something like SSE? I have profiled the application, and I know that this call to Atan is a bottleneck. I know that there is support for this in Open...

Inner angle between two lines

Hi folks, I have two lines: Line1 and Line2. Each line is defined by two points (P1L1(x1, y1), P2L1(x2, y2) and P1L1(x1, y1), P2L3(x2, y3)). I want to know the inner angle defined by these two lines. For do it I calculate the angle of each line with the abscissa: double theta1 = atan(m1) * (180.0 / PI); double theta2 = atan(m2) * (18...