Advertisement

This is what atan2() does if given two Vector2D points on 2D plane?

Started by February 25, 2014 09:44 AM
11 comments, last by tom_mai78101 10 years, 11 months ago

The 2D part is due to the touch screen coordinates. However, my rotation matrix is for manipulating 3D vertices, where the angle theta is required. It's a touchscreen FPS app after all.

I need to find the angle from the X axis to the red line. I don't understand how (cos(angle), sin(angle) = normalized(P2-P1) when the angle is arbitrary in the range 0 degrees to 90 degrees. Unless you mean that for given P1 and P2, by doing arccosine and arcsine on the normalized X and Y of the vector, I can obtain the angle?

You keep saying that you need to find the angle, but knowing (cos(angle), sin(angle)) is usually enough. You get that simply from normalizing P2-P1, as you say. If you really need the angle, you can use atan2. The code looks something like this:

Vector2D diff = P2-P1;
float angle = atan2(diff.y,diff.x);
Advertisement
My mind cracked into place. Now, it is obvious to me.

Thank you for all of your time. Problem solved.

This topic is closed to new replies.

Advertisement