Public Group

# Rotate to face function

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

## Recommended Posts

So I have a cube that I want to rotate to face a point in 3D space. I am limited to using x, y, z angles. Does anyone understand how this can be done?

##### Share on other sites
Try this :D

http://lmgtfy.com/?q=rotating+a+3d+cube

##### Share on other sites

If you consider the rotation around each of those angles seperately, you'll see that a rotation around the y axis for example effectively moves the vertices in the xz plane. The line along which the sides of the cube should align can be used as the hypotenuse in basic trigonometry, while either distance in the x or z direction between the origin and the point you want to face can be used as opposite or adjacent side (which one depends on the coordinate system you're using) to compute the sin or cos of the angle.

The above is probably a better advice :)

##### Share on other sites
Quote:
 Original post by kryotechSo I have a cube that I want to rotate to face a point in 3D space. I am limited to using x, y, z angles. Does anyone understand how this can be done?
Are you *sure* you're limited to using x, y, and z angles? (I ask because people often think they have to use Euler angles when in fact they do not.)

##### Share on other sites
Te software I'm using has commands that rotate the object around the x, y , and z axis. It doesn't have any other commands. I guess I need a generic rotate to face function as well, not one just for a cube.

##### Share on other sites
Quote:
 Original post by XeogenTry this :Dhttp://lmgtfy.com/?q=rotating+a+3d+cube

Ok, that was pretty funny. I applaud you on the originality :)

##### Share on other sites
Quote:
 Original post by kryotechTe software I'm using has commands that rotate the object around the x, y , and z axis. It doesn't have any other commands. I guess I need a generic rotate to face function as well, not one just for a cube.
What software is it?

##### Share on other sites
DarkBASIC Pro (I know, I need to get away from it).

##### Share on other sites
If you're really only able to use Euler angles for this, you can compute a pair of spherical angles from the vector from the box position to the target position using a Cartesian-to-spherical-coordinate conversion. (You only need two angles for this, so you can ignore the third.)

How to perform the conversion will depend on what conventions you're using (e.g. which axis is up), but will generally reduce to a couple of calls to (e.g.) atan2().

1. 1
2. 2
Rutin
22
3. 3
4. 4
JoeJ
16
5. 5

• 14
• 29
• 11
• 11
• 9
• ### Forum Statistics

• Total Topics
631775
• Total Posts
3002277
×