Draw two interlocked tetrahedrons defined by a cube using WPF and C#

interlocked tetrahedrons defined by a cube

This example shows how to draw two interlocked tetrahedrons defined by a cube. (The earlier post Draw interlocked tetrahedrons using XAML and C# draws two interlocked tetrahedrons, but they’re not defined by a cube.)



If you like math, you can explicitly calculate the locations of the vertices that define two interlocked tetrahedrons, but there’s an easier way to figure out where the vertices need to be. You can use the corners of a cube to define the vertices of two interlocked tetrahedrons as shown in the picture on the right.

Much of this example is similar to the previous post, except this version uses the following code to define its tetrahedrons’ vertices and faces.

<!-- Tetrahedron 1 -->
...
<MeshGeometry3D 
Positions="
     1, 1, 1    -1,-1, 1     1,-1,-1
     1, 1, 1    -1, 1,-1    -1,-1, 1
     1, 1, 1     1,-1,-1    -1, 1,-1
    -1,-1, 1    -1, 1,-1     1,-1,-1
"
TriangleIndices="
     0  1  2     3  4  5
     6  7  8     9 10 11
"/>
...

<!-- Tetrahedron 2 -->
...
<MeshGeometry3D 
Positions="
    -1,-1,-1    -1, 1, 1     1, 1,-1
    -1,-1,-1     1,-1, 1    -1, 1, 1
    -1,-1,-1     1, 1,-1     1,-1, 1
     1,-1, 1     1, 1,-1    -1, 1, 1
"
TriangleIndices="
     0  1  2     3  4  5
     6  7  8     9 10 11
"/>
...

If you look carefully at the vertex coordinates, you can see where they lie on the unit cube. The program uses a ScaleTransform3D to scale the coordinates by a factor of 3 in the X, Y, and Z directions to the tetrahedrons fill the viewing area nicely. Download the example for additional details.


Download Example   Follow me on Twitter   RSS feed   Donate


This entry was posted in algorithms, geometry, graphics, mathematics, wpf, XAML and tagged , , , , , , , , , , , , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *