开发者

Calculate rotation between two Vector2s around a pivot

Calculate rotation between two Vector2s around a pivot

Hello 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 开发者_如何学JAVAaround 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.


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;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜