Draw interlocked tetrahedrons using XAML and C#

Draw interlocked tetrahedrons

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 three-dimensional 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.

        <ScaleTransform3D ScaleX="2"
            ScaleY="2" ScaleZ="2" />
        <TranslateTransform3D OffsetY="-0.77"/>

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.

        <ScaleTransform3D ScaleX="2" ScaleY="-2" ScaleZ="2" />
                <AxisAngleRotation3D Axis="0,1,0" Angle="45"/>
        <TranslateTransform3D OffsetY="0.77"/>

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 three-dimensional 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 Example   Follow me on Twitter   RSS feed   Donate

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

2 Responses to Draw interlocked tetrahedrons using XAML and C#

  1. Draw three interlocked boxes using WPF and XAML

    The example Draw two interlocked tetrahedrons using WPF, XAML, and C# draws two small tetrahedrons and uses transformations to make them overlap. This example uses a similar technique. It draws three cubes and scales them so they overlap. The following code shows how the program defines a single cube centered at the origin and with vertex coordinates (

  2. Pingback: Draw two interlocked tetrahedrons defined by a cube

Leave a Reply

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