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[] v = new Vertex[6]; 039 v[0] = new Vertex( 1, 0, 0); // four vertices around the center plane 040 v[1] = new Vertex( 0, 0, -1); 041 v[2] = new Vertex(-1, 0, 0); 042 v[3] = new Vertex( 0, 0, 1); 043 v[4] = new Vertex( 0, 1, 0); // vertex at the top 044 v[5] = new Vertex( 0, -1, 0); // vertex at the bottom 045/* 046 // These vertices create an Octahedron with side length 1. 047 double sqrt3 = Math.sqrt(3.0); 048 double sqrt2 = Math.sqrt(2.0); 049 Vertex[] v = new Vertex[6]; 050 v[0] = new Vertex( 0.5, 0, 0.5); // four vertices around the center plane 051 v[1] = new Vertex(-0.5, 0, 0.5); 052 v[2] = new Vertex(-0.5, 0, -0.5); 053 v[3] = new Vertex( 0.5, 0, -0.5); 054 v[4] = new Vertex( 0, 1/sqrt2, 0); // vertex at the top 055 v[5] = new Vertex( 0, -1/sqrt2, 0); // vertex at the bottom 056*/ 057 // Create 12 line segments. 058 // four line segments around the center plane 059 addLineSegment(new LineSegment(new Vertex(v[0]), new Vertex(v[1]))); 060 addLineSegment(new LineSegment(new Vertex(v[1]), new Vertex(v[2]))); 061 addLineSegment(new LineSegment(new Vertex(v[2]), new Vertex(v[3]))); 062 addLineSegment(new LineSegment(new Vertex(v[3]), new Vertex(v[0]))); 063 // edges going to the top vertex 064 addLineSegment(new LineSegment(new Vertex(v[0]), new Vertex(v[4]))); 065 addLineSegment(new LineSegment(new Vertex(v[1]), new Vertex(v[4]))); 066 addLineSegment(new LineSegment(new Vertex(v[2]), new Vertex(v[4]))); 067 addLineSegment(new LineSegment(new Vertex(v[3]), new Vertex(v[4]))); 068 // edges going to the bottom vertex 069 addLineSegment(new LineSegment(new Vertex(v[0]), new Vertex(v[5]))); 070 addLineSegment(new LineSegment(new Vertex(v[1]), new Vertex(v[5]))); 071 addLineSegment(new LineSegment(new Vertex(v[2]), new Vertex(v[5]))); 072 addLineSegment(new LineSegment(new Vertex(v[3]), new Vertex(v[5]))); 073 } 074}//Octahedron