Advertisement
Luninariel

289 - Tetrahedron

Apr 8th, 2019
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.11 KB | None | 0 0
  1. //
  2. //  Tetrahedron.java
  3. //  Easel
  4. //
  5. //  Created by Philip Rhodes on 8/2/05.
  6. //  Copyright 2005 Philip J Rhodes. All rights reserved.
  7. //
  8.  
  9.  
  10. /*
  11.  * This class represents a tetredron. It is placed on the zero plane
  12.  *  with its top vertex on the y axis. On the base, two points are placed
  13.  *  symmetrically on either side of the positive z axis, and the third
  14.  *  point is placed behind, on the negative z axis.
  15.  */
  16. public class Tetrahedron extends Shape{
  17.  
  18.  
  19.    public Tetrahedron(float size){
  20.    
  21.       // This shape needs 4 vertices and 4 triangles.
  22.       super(4, 4);
  23.      
  24.       this.setScales(size, size, size);
  25.          
  26.       float d = (float) (1/(2*Math.cos(Math.PI/6)));
  27.      
  28.       setVertex(0,   0,     (float) Math.sqrt(1-d*d),  0);
  29.       setVertex(1,   0,     0,                        -d);
  30.      
  31.       setVertex(2,   0.5f,  0, (float) Math.tan(Math.PI/6)/2);
  32.       setVertex(3,   -0.5f, 0, (float) Math.tan(Math.PI/6)/2);
  33.  
  34.       // CCW Winding Order
  35.       setTriangle(0, 1, 2, 3);
  36.       setTriangle(1, 0, 2, 1);
  37.       setTriangle(2, 0, 1, 3);
  38.       setTriangle(3, 0, 3, 2);
  39.    
  40.    }
  41.  
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement