001/*
002
003*/
004
005package renderer.models;
006import  renderer.scene.*;
007
008/**
009   Create a wireframe model of a regular icosahedron
010   with its center at the origin, having edge length
011   <pre>{@code
012     4/(1+sqrt(5)) = 1.2361,
013   }</pre>
014   and with its vertices on a sphere of radius
015   <pre>{@code
016     4/(1+sqrt(5)) * sin(2Pi/5) = 1.1756.
017   }</pre>
018<p>
019   See <a href="https://en.wikipedia.org/wiki/Regular_icosahedron" target="_top">
020                https://en.wikipedia.org/wiki/Regular_icosahedron</a>
021
022   @see Tetrahedron
023   @see Cube
024   @see Octahedron
025   @see Dodecahedron
026*/
027public class Icosahedron extends Model
028{
029   /**
030      Create a regular icosahedron with its center at
031      the origin, having edge length
032      <pre>{@code
033        4/(1+sqrt(5)) = 1.2361,
034      }</pre>
035      and with its vertices on a sphere of radius
036      <pre>{@code
037        4/(1+sqrt(5)) * sin(2Pi/5) = 1.1756.
038      }</pre>
039   */
040   public Icosahedron()
041   {
042      super();
043
044      // Create the icosahedron's geometry.
045      // It has 12 vertices and 30 edges.
046      double t = (1 + Math.sqrt(5))/2;  // golden ratio
047      double r = 1/t;
048      //https://en.wikipedia.org/wiki/Regular_icosahedron#Cartesian_coordinates
049      // All cyclic permutations of (0, ±r, ±1).
050      Vertex v00 = new Vertex(-r,  1,  0);
051      Vertex v01 = new Vertex( r,  1,  0);
052      Vertex v02 = new Vertex(-r, -1,  0);
053      Vertex v03 = new Vertex( r, -1,  0);
054      Vertex v04 = new Vertex( 0, -r,  1);
055      Vertex v05 = new Vertex( 0,  r,  1);
056      Vertex v06 = new Vertex( 0, -r, -1);
057      Vertex v07 = new Vertex( 0,  r, -1);
058      Vertex v08 = new Vertex( 1,  0, -r);
059      Vertex v09 = new Vertex( 1,  0,  r);
060      Vertex v10 = new Vertex(-1,  0, -r);
061      Vertex v11 = new Vertex(-1,  0,  r);
062/*
063      // These vertices create a icosahedron with edge length 2,
064      // and vertices on a sphere of radius
065      //    sqrt(10+2sqrt(5))/2 = 2sin(2Pi/5) = 1.90211.
066      //https://en.wikipedia.org/wiki/Regular_icosahedron#Cartesian_coordinates
067      // All cyclic permutations of (0, ±1, ±t).
068      Vertex v00 = new Vertex(-1,  t,  0);
069      Vertex v01 = new Vertex( 1,  t,  0);
070      Vertex v02 = new Vertex(-1, -t,  0);
071      Vertex v03 = new Vertex( 1, -t,  0);
072      Vertex v04 = new Vertex( 0, -1,  t);
073      Vertex v05 = new Vertex( 0,  1,  t);
074      Vertex v06 = new Vertex( 0, -1, -t);
075      Vertex v07 = new Vertex( 0,  1, -t);
076      Vertex v08 = new Vertex( t,  0, -1);
077      Vertex v09 = new Vertex( t,  0,  1);
078      Vertex v10 = new Vertex(-t,  0, -1);
079      Vertex v11 = new Vertex(-t,  0,  1);
080*/
081      // Create 30 line segments.
082      // To figure out the edges, look at the orthogonal projection in the z-direction.
083      // https://en.wikipedia.org/wiki/Regular_icosahedron#Orthogonal_projections
084
085      // The edge from v00 to v01 is the top horizontal edge.
086      // The edge from v02 to v03 is the bottom horizontal edge.
087      // The edge from v04 to v05 is the front vertical edge.
088      // The edge from v06 to v07 is the back vertical edge.
089      // The edge from v08 to v09 is the right horizontal edge.
090      // The edge from v10 to v11 is the left horizontal edge.
091
092      // Working, more or less, from the top down.
093      addLineSegment(v00, v01);
094      addLineSegment(v00, v05);
095      addLineSegment(v00, v07);
096      addLineSegment(v00, v11);
097      addLineSegment(v00, v10);
098      addLineSegment(v01, v05);
099      addLineSegment(v01, v07);
100      addLineSegment(v01, v09);
101      addLineSegment(v01, v08);
102      addLineSegment(v05, v11);
103      addLineSegment(v05, v09);
104      addLineSegment(v05, v04);
105      addLineSegment(v07, v10);
106      addLineSegment(v07, v08);
107      addLineSegment(v07, v06);
108      addLineSegment(v11, v10);
109      addLineSegment(v11, v04);
110      addLineSegment(v11, v02);
111      addLineSegment(v09, v08);
112      addLineSegment(v09, v04);
113      addLineSegment(v09, v03);
114      addLineSegment(v10, v06);
115      addLineSegment(v10, v02);
116      addLineSegment(v08, v06);
117      addLineSegment(v08, v03);
118      addLineSegment(v04, v02);
119      addLineSegment(v04, v03);
120      addLineSegment(v06, v02);
121      addLineSegment(v06, v03);
122      addLineSegment(v02, v03);
123   }
124}//Icosahedron