# [SOLVED] 2d cordinate rotation in 3d space

This topic is 2288 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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?

##### Share on other sites

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.

##### Share on other sites
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. Edited by FLeBlanc

##### Share on other sites
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.

1. 1
2. 2
Rutin
19
3. 3
khawk
18
4. 4
5. 5
A4L
11

• 12
• 16
• 26
• 10
• 44
• ### Forum Statistics

• Total Topics
633767
• Total Posts
3013739
×

## Important Information

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!