angle in a circle

Started by
12 comments, last by alvaro 16 years, 7 months ago
Quote:Original post by markww
Hmm if it's from the positive x-axis, then shouldn't:

    atan2(4.0, -0.3);


be greater than 90 degrees since it is already in quadrant II? I'm probably mis-using it -
Remember that (in C++ at least), the return value of atan2() is in radians.
Advertisement
Quote:Original post by OrenGL
There is a 2d version of the cross product that gives a scalar... Oh my rusty brain...

It's called "perpdot".
John BoltonLocomotive Games (THQ)Current Project: Destroy All Humans (Wii). IN STORES NOW!
For two vectors a and b,
a dot b = |a| * |b| * cos(angle)
And you know the lengths of the vectors (=radius).


Therefore,
cos(angle) = (a dot b) / r2
So you can find the angle using the acos() function.


Edit: Sorry didn't notice that one of the vectors is always along the X axis. In that case the atan2() methods are perfect. You can use the above method using cosines if you need to find the angle between any two points on the circle.

[Edited by - Verminox on October 15, 2007 9:00:55 AM]
--------------------------------------Amaze your friends! Astound your family! Kennify your text!
The "acos of the dot product" solution has the advantage that it works for vectors in more dimensions. It has the disadvantage that it doesn't give you a sign.

If you are familiar with complex numbers, you can represent both points by complex numbers (representing point (x,y) as x+iy) and then the ratio of both numbers is a complex number whose argument is the angle you are looking for. Again, use atan2() to extract the argument.

Oh, and you should get in the habit of using radians for everything, at least internally in your programs. If you ever need to display the angle for a user to see, then you can multiply it by 180/PI before you show it.

This topic is closed to new replies.

Advertisement