001/* 002 003*/ 004 005package renderer.models; 006import renderer.scene.*; 007 008/** 009 Create a wireframe model of a tetrahedron as a 010 triangular pyramid with an equilateral triangle 011 base (centered at the origin in the xz-plane) 012 whose three vertices are connected to a 4th vertex 013 on the positive y-axis. 014 015 @see Tetrahedron 016*/ 017public class TriangularPyramid extends Model 018{ 019 /** 020 Create a regular tetrahedron having side length 021 {@code sqrt(3)/sqrt(2)}, with one face in the 022 xz-plane with its center at the origin, and the 023 4th vertex on the positive y-axis at height 1. 024 */ 025 public TriangularPyramid() 026 { 027 this(Math.sqrt(3)/Math.sqrt(2)); // makes the height = 1 028 //or 029 //this(Math.sqrt(3)); // make the height = sqrt(2) > 1 030 } 031 032 033 /** 034 Create a regular tetrahedron having side length {@code s}, 035 with one face in the xz-plane with its center at the origin, 036 and with the 4th vertex on the positive y-axis at 037 height {@code s*sqrt(2)/sqrt(3)}. 038 039 @param s the length of the regular tetrahedron's sides 040 */ 041 public TriangularPyramid(double s) 042 { 043 this(s/Math.sqrt(3), s*Math.sqrt(2)/Math.sqrt(3)); 044 } 045 046 047 /** 048 Create a tetrahedron with one face being an equilateral triangle 049 inscribed in a circle of radius {@code r} centered at the origin 050 of the xz-plane and with the 4th vertex on the y-axis at height 051 {@code h}. 052 <p> 053 If {@code h = r * sqrt(2)}, then the tetrahedron is a regular tetrahedron. 054 with side length {@code s = r * sqrt(3)}. 055 <p> 056 Another way to state this is, if an equilateral triangle is inscribed 057 in a circle of radius {@code r}, then the edge length of the triangle 058 is {@code r*sqrt(3)} and the height of the regular tetrahedron made 059 from the triangle is {@code r*sqrt(2)}. 060 061 @param r radius of circle in xz-plane that the equilateral base is inscribed in 062 @param h coordinate on the y-axis of the apex 063 */ 064 public TriangularPyramid(double r, double h) 065 { 066 super(); 067 068 // Create the tetrahedron's geometry. 069 double sqrt3 = Math.sqrt(3.0); 070 Vertex v0 = new Vertex( r, 0, 0); // three vertices around the bottom face 071 Vertex v1 = new Vertex(-r/2, 0, r*0.5*sqrt3); 072 Vertex v2 = new Vertex(-r/2, 0, -r*0.5*sqrt3); 073 Vertex v3 = new Vertex( 0, h, 0); // vertex at the top 074 075 // Create 6 line segments. 076 // bottom face 077 addLineSegment(v0, v1); 078 addLineSegment(v1, v2); 079 addLineSegment(v2, v0); 080 // edge 1 081 addLineSegment(v0, v3); 082 // edge 2 083 addLineSegment(v1, v3); 084 // edge 3 085 addLineSegment(v2, v3); 086 } 087}//TriangularPyramid