I am rotating an image around it center point but need to track a location on the image as it rotates.
Given:
- Origin at 0,0
- Image width and height of 100, 100
- Rotation point at C(5开发者_运维技巧0,50)
- Angle of "a" (say 90 degrees in this example)
- Point P starts at (25,25) and after the rotation it is at Pnew(75,25)
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...)
精彩评论