[SOLVED] 2d cordinate rotation in 3d space

Started by
2 comments, last by Sollum 11 years, 7 months ago

Good afternoon!

I am stuck on a little math problem and i dont know how to solve it.
I want to force Object A rotate around Object B. 2d math does it well.

x = -sin(angle) * distanceFromTarget + target->x
y = cos(angle) * distanceFromTarget + target->y
z = target->z

Everything works fine. But i have no idea how to adjust the angle of orbit math wise. I can simply do stuff like glRotatef(90, 1, 0, 0) and it will do the trick, but i want to have exact cords without using GL calls. Furthermore, i dont want to be bound only to one axis.

To make my question more precise - How to "bend" my orbit mathematically?

Advertisement

Good afternoon!

I am stuck on a little math problem and i dont know how to solve it.
I want to force Object A rotate around Object B. 2d math does it well.

x = -sin(angle) * distanceFromTarget + target->x
y = cos(angle) * distanceFromTarget + target->y
z = target->z

Everything works fine. But i have no idea how to adjust the angle of orbit math wise. I can simply do stuff like glRotatef(90, 1, 0, 0) and it will do the trick, but i want to have exact cords without using GL calls. Furthermore, i dont want to be bound only to one axis.

To make my question more precise - How to "bend" my orbit mathematically?


I'm not sure what you mean. If you want to change your angle around of the object orbiting another object all you have to do is change the angle variable in your equation then use glTranslate to move the object (make sure you call glLoadIdentity() every update). Or, you could just do glRotate but it depends what you want to do. Using glTranslate then glRotate probably mess everything up so make sure it's the other way around. Also, you can just have a separate angle of each axis so your call is not bound to a single axis. For instance, glRotate(xAngle,etc); glRotate(yAngle, etc);
Not sure what you're asking though so if you could reword it then that would be easier to answer.
Rotations are performed around an axis. 2D rotation is a simplified form of 3D, in which the axis around which the rotation is performed is a conceptual axis extending normal to the 2D plane. IE, if your 2D plane is the XY plane, the axis of rotation is the Z axis. Z coordinates are "ignored", and the math simplifies down to a simple transformation.

In 3D, it gets a bit more complicated because the rotation can be performed around any arbitrary axis. Using axis-angle rotation, you simply need to establish the axis around which you want to rotate, and specify the angle of rotation.
Thanks! Found this awesome weby to clear things up.

http://www.siggraph.org/education/materials/HyperGraph/modeling/mod_tran/3drota.htm

Tho i only need to figure out how to do rotation between two axes.

This topic is closed to new replies.

Advertisement