Polygon Rotation
Ok, this ones a little tricky.
We have the following:
struct POINT{
float x,y;
}
struct POLY{
vector PtArray;
}
I want to rotate the POLY around a POINT, not neccesarily the origin, N degrees. I dont want to switch to Polar coords if I dont have to. Any ideas on code?
Tx-
Here''s what i would do:
If the point is not the origin, then make it the origin (this sounds like ZEN ehm?).
If you want to rotate your polygon arround a point P(x,y)=(20,20) (for example), then subtract to all the points in your polygon the point P (thus, making a translaction). Then rotate each point in your polygon n degrees. After your done with rotations, you''ll have to "de-translacte" -> sum to every point in your polygon the point P again.
I think this will work....
If the point is not the origin, then make it the origin (this sounds like ZEN ehm?).
If you want to rotate your polygon arround a point P(x,y)=(20,20) (for example), then subtract to all the points in your polygon the point P (thus, making a translaction). Then rotate each point in your polygon n degrees. After your done with rotations, you''ll have to "de-translacte" -> sum to every point in your polygon the point P again.
I think this will work....
I''ve just spent the last half hour revising my basic maths skills (I haven''t done this stuff since 1994), and came up with something like this:
for each point in the polygon
Px <- Rx + (Px - Rx) cos N + (Py - Ry) sin N
Py <- Ry + (Py - Ry) cos N + (Px - Rx) sin N
where (Px,Py) is your current point, and (Rx,Ry) is the point you are rotating about (<- means takes the value). This is in line with what wolverine posted while I was away figuring it out ;-)
--
Get a stripper on your desktop!
for each point in the polygon
Px <- Rx + (Px - Rx) cos N + (Py - Ry) sin N
Py <- Ry + (Py - Ry) cos N + (Px - Rx) sin N
where (Px,Py) is your current point, and (Rx,Ry) is the point you are rotating about (<- means takes the value). This is in line with what wolverine posted while I was away figuring it out ;-)
--
Get a stripper on your desktop!
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement