Title: Draw interlocked tetrahedrons using XAML and C#
This example shows how you can draw interlocked tetrahedrons using XAML and C#. The example Rotate a tetrahedron with crisp edges using XAML and C# shows how to draw a threedimensional tetrahedron. This example uses the same code to define the points and triangles that make up a tetrahedron. It repeats that to define two different tetrahedrons with only three small changes.
First, it changes the colors of the tetrahedrons so it's easier to tell them apart.
Second, it adds the following Transform to the first (blue) tetrahedron.
<GeometryModel3D.Transform>
<Transform3DGroup>
<ScaleTransform3D ScaleX="2"
ScaleY="2" ScaleZ="2" />
<TranslateTransform3D OffsetY="0.77"/>
</Transform3DGroup>
</GeometryModel3D.Transform>
A Transform can only contain a single transformation. Because this example needs to apply multiple transformations to the tetrahedron, this Transform contains a Transform3D group. That group can then contain as many transformations as you need.
In this example, the group contains a scale transformation that enlarges the tetrahedron by a factor of 2 in the X, Y, and Z directions, basically doubling its size. (The previous example also included that transformation.)
The group also contains a translation transformation that moves the tetrahedron 0.77 units in the negative Y direction.
The third way this example differs from the previous example is it applies the following Transform to the second (yellow) tetrahedron.
<GeometryModel3D.Transform>
<Transform3DGroup>
<ScaleTransform3D ScaleX="2" ScaleY="2" ScaleZ="2" />
<RotateTransform3D>
<RotateTransform3D.Rotation>
<AxisAngleRotation3D Axis="0,1,0" Angle="45"/>
</RotateTransform3D.Rotation>
</RotateTransform3D>
<TranslateTransform3D OffsetY="0.77"/>
</Transform3DGroup>
</GeometryModel3D.Transform>
This Transform scales the tetrahedron by a factor of 2 in the X and Z directions, and by a factor of 2 in the Y direction to flip the tetrahedron upside down.
It also includes a RotateTransform. That transform's Rotation property contains an AxisAngleRotation3D object that defines the rotation. It rotates the shape around the Y axis <0, 1, 0> through an angle of 45 degrees, so the tetrahedrons aren't facing the same direction.
The Transform finishes by translating the tetrahedron by 0.77 units in the positive Y direction.
This example demonstrates an important technique in building threedimensional scenes. It starts with a basic object, in this case a small tetrahedron, and then uses transformations to scale, rotate, and translate the object as needed to produce new objects.
Download the example to experiment with it and to see additional details.
