• Create Account

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

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

3 replies to this topic

### #1Sollum  Members   -  Reputation: 396

Like
0Likes
Like

Posted 12 September 2012 - 08:03 AM

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?

Edited by Sollum, 12 September 2012 - 02:09 PM.

### #2CryoGenesis  Members   -  Reputation: 440

Like
1Likes
Like

Posted 12 September 2012 - 09:14 AM

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.

### #3FLeBlanc  Members   -  Reputation: 2032

Like
1Likes
Like

Posted 12 September 2012 - 09:24 AM

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, 12 September 2012 - 09:26 AM.

### #4Sollum  Members   -  Reputation: 396

Like
0Likes
Like

Posted 12 September 2012 - 02:10 PM

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.

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

PARTNERS