Rotation of Tetrehedra for 3d Tessellation
I'm trying to render some 3d graphics with a bunch of tetrahedra. I'm 开发者_高级运维trying to figure out how to rotate one tetrahedron such that it will be perfectly face-to-face with another tetrahedron. If this is confusing, multiple tetrahedra touching face to face would look like this.
I'm using OpenGL to programmatically rotate objects, so I can only rotate on one of the three axes at a time. For example, I can rotate clockwise 20 degrees on X, then counterclockwise 45 degrees on Z, etc.
I understand the programming aspect of this program (using OpenGL's glRotatef() function to rotate on one axis at a time), but am more interested in the specific angles needed for each axis in order to achieve the 3d tessellation.
Thanks for any help, let me know if you need more clarification.
If they need to be perfectly face to face, I would not try to find a rotation at all.
Instead, I would start with one tetrahedron. Decide which face is shared with the next one.
Take the cross product of two edges on this face (50% chance that it points in the direction of the 4th point, in this case invert the vector). Normalize. Multiply by sqrt(6)/3 * edge_length (this is a constant, precompute!).
You now have a vector pointing in the direction of the new tetrahedron's 4th vertex (the other 3 you already know, they're the same as the ones on the face!), with the length of the new tetrahedron's height.
All you now need is an origin for your vector: Take the arithmetic mean of the coordinates of the 3 shared vertices, that will give the center point of that face.
Add the vector to that point, giving you the final point.
Now you two tetrahedrons sharing one face (regardless of orientation), no rotation math needed.
精彩评论