开发者

Calculate the rotation performed around a point

I have two points in 2D space, centred on origin (0,0). The first point represents the starting location and the second represents the end location. I need to calculate the angle of rotation between the two points, my problem being that the hypoteneuse from each point to (0,0) is not equal.

Could someone tell me how to work out the angle between the two points, bearing in mind that they could be anywhere 开发者_JAVA百科relative to (0,0).

Many thanks,

Matt.


Let's say point 1 is (x1,y1) and point 2 is (x2,y2)

The tangent of the Angle from X axis to point 1, relative to (0,0) is y1/x1

The tangent of the Angle from X axis to point 2, relative to (0,0) is y2/x2

Take the arc tangent (is that the right term? Tan-1 on a calculator) to get the actual angle for each, then subtract to get the answer you're looking for


This is easily accomplished taking the arccosine of the normalized inner product of the two vectors. That is, given u = (ux, uy) and v = (vx, vy), the angle between the two is given by θ = acos(u·v/|u||v|), where u · v = uxvx + uyvy is the dot product of the two and the | | operator is the l2 normal given by |u| = sqrt(ux2 + uy2). This will result in the smallest rotation that can be applied to one of the vectors that will make them linear multiples of each other. Therefore, you may need to fiddle with the sign of θ to make sure you're going in the right direction if you have one you want to start from.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜