001/*
002
003*/
004
005package renderer.models;
006import  renderer.scene.*;
007
008/**
009   Create a wireframe model of a regular tetrahedron
010   with its center at the origin, having edge length
011   {@code 2*sqrt(2)}, and with its vertices at corners
012   of the cube with vertices {@code (±1, ±1, ±1)}.
013<p>
014   See <a href="http://en.wikipedia.org/wiki/Tetrahedron" target="_top">
015                http://en.wikipedia.org/wiki/Tetrahedron</a>
016
017   @see Cube
018   @see Octahedron
019   @see Icosahedron
020   @see Dodecahedron
021*/
022public class Tetrahedron extends Model
023{
024   /**
025      Create a regular tetrahedron with its center at
026      the origin, having edge length {@code 2*sqrt(2)},
027      and with its vertices at corners of the cube with
028      vertices {@code (±1, ±1, ±1)}.
029   */
030   public Tetrahedron()
031   {
032      this(false);
033   }
034
035
036   /**
037      Create a regular tetrahedron or its dual tetrahedron
038      (the dual of a tetrahedron is another tetrahedron).
039   <p>
040      <a href="https://en.wikipedia.org/wiki/Tetrahedron#Regular_tetrahedron" target="_top">
041               https://en.wikipedia.org/wiki/Tetrahedron#Regular_tetrahedron</a>
042   <p>
043      The combination of these two dual tetrahedrons is a stellated octahedron.
044   <p>
045      <a href="https://en.wikipedia.org/wiki/Stellated_octahedron" target="_top">
046               https://en.wikipedia.org/wiki/Stellated_octahedron</a>
047
048      @param dual  choose between the two dual tetrahedrons
049   */
050   public Tetrahedron(boolean dual)
051   {
052      super();
053
054      // Create the tetrahedron's geometry.
055      // It has 4 vertices and 6 edges.
056      Vertex v0, v1, v2, v3;
057      if ( ! dual)
058      {
059         v0 = new Vertex( 1,  1,  1);
060         v1 = new Vertex(-1,  1, -1);
061         v2 = new Vertex( 1, -1, -1);
062         v3 = new Vertex(-1, -1,  1);
063      }
064      else // create the dual tetrahedron by
065      {    // inverting the coordinates given above
066         v0 = new Vertex(-1, -1, -1);
067         v1 = new Vertex( 1, -1,  1);
068         v2 = new Vertex(-1,  1,  1);
069         v3 = new Vertex( 1,  1, -1);
070      }
071
072      // Create 6 line segments.
073      addLineSegment(v0, v1);//top (bottom) edge
074      addLineSegment(v2, v3);//bottom (top) edge
075      addLineSegment(v0, v2);
076      addLineSegment(v0, v3);
077      addLineSegment(v1, v2);
078      addLineSegment(v1, v3);
079   }
080}//Tetrahedron