001/*
002
003*/
004
005package renderer.models;
006import  renderer.scene.*;
007
008/**
009   Create a wireframe model of a regular octahedron
010   with its center at the origin, having side length
011   {@code  sqrt(2) = 1.4142},with its center plane given
012   by the four vertices {@code  (±1, 0, ±1)}. and with
013   the top and bottom vertices being {@code  (0, ±1, 0)}.
014<p>
015   See <a href="http://en.wikipedia.org/wiki/Octahedron" target="_top">
016                http://en.wikipedia.org/wiki/Octahedron</a>
017
018   @see Tetrahedron
019   @see Cube
020   @see Icosahedron
021   @see Dodecahedron
022*/
023public class Octahedron extends Model
024{
025   /**
026      Create a regular octahedron with its center at the
027      origin, having side length {@code  sqrt(2) = 1.4142},
028      with its center plane given by the four vertices
029      {@code  (±1, 0, ±1)}. and with the top and bottom
030      vertices being {@code  (0, ±1, 0)}.
031   */
032   public Octahedron()
033   {
034      super();
035
036      // Create the octahedron's geometry.
037      // It has 6 vertices and 12 edges.
038      Vertex v0 = new Vertex( 1,  0,  0); // four vertices around the center plane
039      Vertex v1 = new Vertex( 0,  0, -1);
040      Vertex v2 = new Vertex(-1,  0,  0);
041      Vertex v3 = new Vertex( 0,  0,  1);
042      Vertex v4 = new Vertex( 0,  1,  0); // vertex at the top
043      Vertex v5 = new Vertex( 0, -1,  0); // vertex at the bottom
044/*
045      // These vertices create an Octahedron with side length 1.
046      double sqrt3 = Math.sqrt(3.0);
047      double sqrt2 = Math.sqrt(2.0);
048      v0 = new Vertex( 0.5, 0,  0.5);  // four vertices around the center plane
049      v1 = new Vertex(-0.5, 0,  0.5);
050      v2 = new Vertex(-0.5, 0, -0.5);
051      v3 = new Vertex( 0.5, 0, -0.5);
052      v4 = new Vertex( 0,  1/sqrt2, 0);   // vertex at the top
053      v5 = new Vertex( 0, -1/sqrt2, 0);   // vertex at the bottom
054*/
055      // Create 12 line segments.
056      // four line segments around the center plane
057      addLineSegment(v0, v1);
058      addLineSegment(v1, v2);
059      addLineSegment(v2, v3);
060      addLineSegment(v3, v0);
061      // edges going to the top vertex
062      addLineSegment(v0, v4);
063      addLineSegment(v1, v4);
064      addLineSegment(v2, v4);
065      addLineSegment(v3, v4);
066      // edges going to the bottom vertex
067      addLineSegment(v0, v5);
068      addLineSegment(v1, v5);
069      addLineSegment(v2, v5);
070      addLineSegment(v3, v5);
071   }
072}//Octahedron