Rotation
If this is for a 3d app, then you don't need to do the math yourself. The 3d library that you are using will have some functions to take care of this for you. OpenGL example: glRotatef().
If you are working on a project where you don't have a 3d library to use, then you can use these steps to rotate a point around:
- First the x, y coords relative to the point of rotation.
- Convert these "rectangular" coords into polar coordinates where you have an angle and then a distance from orgin.
- Increase or decrease the angle part depening upon how much you want to rotate your point.
- Convert back to the rectangular coodinate system.
[edited by - WhtRbt on November 26, 2002 3:51:58 PM]
If you are working on a project where you don't have a 3d library to use, then you can use these steps to rotate a point around:
- First the x, y coords relative to the point of rotation.
- Convert these "rectangular" coords into polar coordinates where you have an angle and then a distance from orgin.
- Increase or decrease the angle part depening upon how much you want to rotate your point.
- Convert back to the rectangular coodinate system.
[edited by - WhtRbt on November 26, 2002 3:51:58 PM]
- Go not to the elves for counsel, for they will say both yes and no.
This is how I usually do it:
x'' + i z'' = (x + i z) * exp(i*Pi/18), where i = sqrt(-1)
Let''s call Pi/18 = a (this is 10 degrees in radians)
exp(i*a) = cos(a) + i * sin(a) // Weird but true
x'' = x*cos(a) - z*sin(a)
z'' = x*sin(a) + z*cos(a)
x'' + i z'' = (x + i z) * exp(i*Pi/18), where i = sqrt(-1)
Let''s call Pi/18 = a (this is 10 degrees in radians)
exp(i*a) = cos(a) + i * sin(a) // Weird but true
x'' = x*cos(a) - z*sin(a)
z'' = x*sin(a) + z*cos(a)
I am rotating a point about the Y axis and drawing a line from the origin to the point. The problem is that the point rotates twice as fast through one half of the circle than the other and the length of my line seems to change slightly. Here''s my code :
vBB[0].x = (vBB[0].x * cosf(a)) + (vBB[0].z * sinf(a));
vBB[0].z = (vBB[0].x * -sinf(a)) + (vBB[0].z * cosf(a));
if (a < 2*PI) a += 2*PI / 360;
else a = 0;
vBB is my vector object and a is a float. Any ideas why
vBB[0].x = (vBB[0].x * cosf(a)) + (vBB[0].z * sinf(a));
vBB[0].z = (vBB[0].x * -sinf(a)) + (vBB[0].z * cosf(a));
if (a < 2*PI) a += 2*PI / 360;
else a = 0;
vBB is my vector object and a is a float. Any ideas why
This may not be the problem, but ask yourself: What is the value of vBB[0].x before I start my calculations, and what is its value after the first line? How does this affect my rotation?"
Later,
ZE.
//email me.//zealouselixir software.//msdn.//n00biez.//
miscellaneous links
Later,
ZE.
//email me.//zealouselixir software.//msdn.//n00biez.//
miscellaneous links
[twitter]warrenm[/twitter]
As i seeit the value of my coords doesn''t matter (its 100 by the way) i just want to rotate an arbitary point around the Y axis.
November 30, 2002 01:36 PM
No, what ZealousElixir means is that VBB[0].x changes before the second line! (hence destroying the rotation formula... you have to put the result in a different variable.
December 01, 2002 07:58 AM
i borrowed the code to do this from an open source analogue clock funily enough... and it worked. you just need to duplicate it for the different dimentions and stuff
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement