2D rotations
Here is my relatively simple problem:
Let''s say we have a line segment defined by two points consisting of four floats(x1,x2,y1,y2), which likely (depending on a level designer) are positive numbers. Let''s say I wish to rotate that line segment by certain number of degrees. I also wish to rotate it by an imaginary pivot point (defined by two floats px and py).
How would I calculate new coordinates for my two points ?
November 24, 2001 08:10 PM
there''s some articles on this type of thing in the articles section
![](smile.gif)
do you mean concatenatig the rotation or one after the other ?
is not so difficult just remember that p=(p0-p1)*M+p1''
where pis the new point , p0 is the pivot, p1 the point''s coordinates, M is the matrix containing the rotation vaule in euler angles, p1'' is the previously rotated point , this formula is usefull when concatenating multiple rotations, before some math guru will flame me , it works because i have used it in my skeletal engine .
byez.
is not so difficult just remember that p=(p0-p1)*M+p1''
where pis the new point , p0 is the pivot, p1 the point''s coordinates, M is the matrix containing the rotation vaule in euler angles, p1'' is the previously rotated point , this formula is usefull when concatenating multiple rotations, before some math guru will flame me , it works because i have used it in my skeletal engine .
byez.
I can''t find exact article you are talking about. Could you direct me ?
I''ll answer concatenation question with an example. If I had a pentagon (defined by 5 separate lines) and I wanted to rotate it 90 degrees left (on supposed z axis, since all this is in 2D), I would have to rotate every line by itself (since I wish to create a flexible class that consists of infinite amount of less complex line objects. These complex objects cannot be predefined nor can they rotate lines that make them up, they can only set same pivot point to all lines and give them an amount by which to rotate).
Other way to see it as a triangle being rotate by its vertex, where vertex is pivot point and base is line that is being rotated.
I''m pretty sure this would allow me to rotate complex objects consisting of many simple lines. I hope there is a simple formula for what I want to do that does not involve matrix operations.
I''ll answer concatenation question with an example. If I had a pentagon (defined by 5 separate lines) and I wanted to rotate it 90 degrees left (on supposed z axis, since all this is in 2D), I would have to rotate every line by itself (since I wish to create a flexible class that consists of infinite amount of less complex line objects. These complex objects cannot be predefined nor can they rotate lines that make them up, they can only set same pivot point to all lines and give them an amount by which to rotate).
Other way to see it as a triangle being rotate by its vertex, where vertex is pivot point and base is line that is being rotated.
I''m pretty sure this would allow me to rotate complex objects consisting of many simple lines. I hope there is a simple formula for what I want to do that does not involve matrix operations.
Rotation involve matrix operation , but matrix operationare just a simpler way to define some kind of equation operation, anyway i think you could try this code
px=x-x0;
py=y-y0;
pz=z-z0;
rx=px * cos(rad) - py * sin(rad) + x0
ry=px * sin(rad) + py * cos(rad) + y0
this code will rotate a point given x,y around a pivot ,x0,y0
of an angle rad , put your point coordinates in an array one for x and one for y, say and array of 100 entryes , then connect the lines and you''ll get your pentagon or whatever
px=x-x0;
py=y-y0;
pz=z-z0;
rx=px * cos(rad) - py * sin(rad) + x0
ry=px * sin(rad) + py * cos(rad) + y0
this code will rotate a point given x,y around a pivot ,x0,y0
of an angle rad , put your point coordinates in an array one for x and one for y, say and array of 100 entryes , then connect the lines and you''ll get your pentagon or whatever
November 26, 2001 07:15 AM
I know the above works, but I don''t know why. Could someone explain?
Just adding that it is faster to only use cos(rad) and sin(rad) once, and assign them to a temp variable.
AP, what part is it that you dont understand ? ..are you familiar with the unit circle ?
![](http://home.online.no/~7396/totallyinsane.gif)
::WARNING:: -stupidity detected
AP, what part is it that you dont understand ? ..are you familiar with the unit circle ?
![](http://home.online.no/~7396/totallyinsane.gif)
::WARNING:: -stupidity detected
November 26, 2001 12:27 PM
http://www.gamedev.net/community/forums/topic.asp?topic_id=66797
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement