开发者

Image rotation & tracking locations

I am rotating an image around it center point but need to track a location on the image as it rotates.

Given:

  1. Origin at 0,0
  2. Image width and height of 100, 100
  3. Rotation point at C(5开发者_运维技巧0,50)
  4. Angle of "a" (say 90 degrees in this example)
  5. Point P starts at (25,25) and after the rotation it is at Pnew(75,25)

Image rotation & tracking locations

I haven't touched trig in 20 years but guessing the formula is simple...


I haven't touched trig in 20 years but guessing the formula is simple...

Yep, fairly. To map the point (x1,y1) via rotation around the origin:

x2 = cos(a) * x1 + sin(a) * y1;
y2 = cos(a) * y1 - sin(a) * x1;

... so you just first need to translate to the origin i.e. (-50,-50) in your example and translate back after rotation.

x2 = cos(a) * (x1 - 50) + sin(a) * (y1 - 50) + 50;
y2 = cos(a) * (y1 - 50) - sin(a) * (x1 - 50) + 50;

... Or something like that. (You can generate a matrix which will do all three transformations, I'll leave that for another answer or as an exercise...)

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜