Nick
Nick

Reputation: 958

Calculate rotation between two Vector2s around a pivot

alt textHello all.

After a good long Sunday google I am going to have to hang my head in shame and ask the question...

What I have is a pivot vector2, a "Previous" vector2 and a "Current" vector2.

I would like to be able to calculate the rotation in radians between them. A slight complication is the fact that the pivot may moved between previous and current but ill deal with the offsetting as a separate issue if you don't have the time to bring that into the fold.

To clarify, an object which has two vectors, a pivot and a base ... the pivot sitting in the centre and the base at the bottom is rotated around an external pivot. I need to work out the rotation of the object itself around its centre using the two mentioned vectors.

Very big thanks to anyone that can help.

Background to problem

I have a game where an object is rotated around an external pivot. By using using two points (one in the centre, one at the base of the object) I am wanting to to work out the rotation that needs to be applied to the objects sprite around its centre to conform to the larger rotation that has been applied.

Upvotes: 1

Views: 868

Answers (1)

SLaks
SLaks

Reputation: 888167

Take the cross product of the differences between the vectors and the pivot:

Vector2 a = Pivot - Previous, b = Current - pivot;
double angle = a.X * b.Y - a.Y * b.X;

Upvotes: 1

Related Questions