Question

I have been trying to get this problem resolved for week and have get to come to a solution. What I have is 2 points in a 2d space, what I need to resolve is what the rotation of one is around the other. With luck the attached diagram will help, what I need to be able to calculate is the rotational value of b around a.

alt text

I have found lots of stuff that points to finding the dot product etc but I am still searching for that golden solution :o(

Thanks!

Was it helpful?

Solution

Vector2 difference = pointB - pointA;

double rotationInRadians = Math.Atan2(difference.Y, difference.X);

See http://msdn.microsoft.com/en-us/library/system.math.atan2.aspx for reference.

OTHER TIPS

A guess:

  • 1.) Find the slope m of the line A, B.
  • 2.) Convert slope to angle theta = arctan(m)
  • 3.) Project the angle to a quadrant in a cartesian coordinate system centered at point A to get the normalized angle

I'll assume that due east (along the X axis, to the right) is zero radians, and that +x points to the right and +y points down.

The bearing of B with respect to A is

angle = Arctan2 [(A_y - B_y) / (B_x - A_x)]

Use the proper function to calculate the proper quadrant (probably Math.Atan2)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top