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