Rotate to face function
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?
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 :)
Quote:Original post by kryotechAre 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.)
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?
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.
Quote:Original post by Xeogen
Try this :D
http://lmgtfy.com/?q=rotating+a+3d+cube
Ok, that was pretty funny. I applaud you on the originality :)
Quote:Original post by kryotechWhat software is it?
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.
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().
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().
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement