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[] v = new Vertex[4];
057      if ( ! dual)
058      {
059         v[0] = new Vertex( 1,  1,  1);
060         v[1] = new Vertex(-1,  1, -1);
061         v[2] = new Vertex( 1, -1, -1);
062         v[3] = new Vertex(-1, -1,  1);
063      }
064      else // create the dual tetrahedron by
065      {    // inverting the coordinates given above
066         v[0] = new Vertex(-1, -1, -1);
067         v[1] = new Vertex( 1, -1,  1);
068         v[2] = new Vertex(-1,  1,  1);
069         v[3] = new Vertex( 1,  1, -1);
070      }
071
072      // Create 6 line segments.
073      addLineSegment(new LineSegment(new Vertex(v[0]), new Vertex(v[1])));//top (bottom) edge
074      addLineSegment(new LineSegment(new Vertex(v[2]), new Vertex(v[3])));//bottom (top) edge
075      addLineSegment(new LineSegment(new Vertex(v[0]), new Vertex(v[2])));
076      addLineSegment(new LineSegment(new Vertex(v[0]), new Vertex(v[3])));
077      addLineSegment(new LineSegment(new Vertex(v[1]), new Vertex(v[2])));
078      addLineSegment(new LineSegment(new Vertex(v[1]), new Vertex(v[3])));
079   }
080}//Tetrahedron