JavaCAD
Tetrahedron.java
Go to the documentation of this file.
1 /*
2  * Tetrahedron.java
3  */
4 package eu.mihosoft.vrl.v3d;
5 
6 import java.util.ArrayList;
7 import java.util.List;
8 
9 import eu.mihosoft.vrl.v3d.ext.quickhull3d.HullUtil;
10 import eu.mihosoft.vrl.v3d.parametrics.LengthParameter;
11 import eu.mihosoft.vrl.v3d.parametrics.Parameter;
12 
13 public class Tetrahedron extends Primitive {
14 
18  private Vector3d center;
22  private double radius;
23 
25  private boolean centered = true;
26 
33  public Tetrahedron() {
34  center = new Vector3d(0, 0, 0);
35  radius = 1;
36  }
37 
44  public Tetrahedron(double size) {
45  center = new Vector3d(0, 0, 0);
46  radius = size;
47  }
48 
56  public Tetrahedron(Vector3d center, double size) {
57  this.center = center;
58  this.radius = size;
59  }
60 
61  /* (non-Javadoc)
62  * @see eu.mihosoft.vrl.v3d.Primitive#toPolygons()
63  */
64  @Override
65  public List<Polygon> toPolygons() {
66  if(radius<=0)
67  throw new NumberFormatException("radius can not be negative");
68  double _1_sqrt2 = 1/Math.sqrt(2);
69 
70  List<Vector3d> points = new ArrayList<>();
71  points.add(new Vector3d(-1,0,-_1_sqrt2));
72  points.add(new Vector3d(+1,0,-_1_sqrt2));
73  points.add(new Vector3d(0,-1,+_1_sqrt2));
74  points.add(new Vector3d(0,+1,+_1_sqrt2));
75 
76  List<Polygon> polygons = HullUtil.hull(points).scale(radius/Math.sqrt(3)).getPolygons();
77 
78  return polygons;
79  }
80 
86  public Vector3d getCenter() {
87  return center;
88  }
89 
96  this.center = center;
97  return this;
98  }
99 
105  public double getRadius() {
106  return radius;
107  }
108 
114  public void setRadius(double radius) {
115  this.radius = radius;
116  }
117 
118  /* (non-Javadoc)
119  * @see eu.mihosoft.vrl.v3d.Primitive#getProperties()
120  */
121  @Override
123  return properties;
124  }
125 
131  centered = false;
132  return this;
133  }
134 
135 }
List< Polygon > getPolygons()
Definition: CSG.java:698
CSG scale(Number scaleValue)
Definition: CSG.java:611
final PropertyStorage properties
void setRadius(double radius)
Tetrahedron(Vector3d center, double size)
Tetrahedron setCenter(Vector3d center)