JavaCAD
Dodecahedron.java
Go to the documentation of this file.
1 
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 
11 public class Dodecahedron extends Primitive {
12 
16  private Vector3d center;
20  private double radius;
21 
23  private boolean centered = true;
24 
31  public Dodecahedron() {
32  center = new Vector3d(0, 0, 0);
33  radius = 1;
34  }
35 
42  public Dodecahedron(double size) {
43  center = new Vector3d(0, 0, 0);
44  radius = size;
45  }
46 
54  public Dodecahedron(Vector3d center, double size) {
55  this.center = center;
56  this.radius = size;
57  }
58 
59  /* (non-Javadoc)
60  * @see eu.mihosoft.vrl.v3d.Primitive#toPolygons()
61  */
62  @Override
63  public List<Polygon> toPolygons() {
64  if(radius<=0)
65  throw new NumberFormatException("radius can not be negative");
66 
67  double phi = (Math.sqrt(5)+1)/2;
68 
69  List<Vector3d> points = new ArrayList<>();
70  points.add(new Vector3d(-1,-1,-1));
71  points.add(new Vector3d(-1,-1,+1));
72  points.add(new Vector3d(-1,+1,-1));
73  points.add(new Vector3d(-1,+1,+1));
74  points.add(new Vector3d(+1,-1,-1));
75  points.add(new Vector3d(+1,-1,+1));
76  points.add(new Vector3d(+1,+1,-1));
77  points.add(new Vector3d(+1,+1,+1));
78  points.add(new Vector3d(0,1/phi,phi));
79  points.add(new Vector3d(0,-1/phi,phi));
80  points.add(new Vector3d(phi,0,1/phi));
81  points.add(new Vector3d(1/phi,phi,0));
82  points.add(new Vector3d(-1/phi,phi,0));
83  points.add(new Vector3d(-phi,0,1/phi));
84  points.add(new Vector3d(1/phi,-phi,0));
85  points.add(new Vector3d(phi,0,-1/phi));
86  points.add(new Vector3d(0,1/phi,-phi));
87  points.add(new Vector3d(-phi,0,-1/phi));
88  points.add(new Vector3d(-1/phi,-phi,0));
89  points.add(new Vector3d(0,-1/phi,-phi));
90 
91  List<Polygon> polygons = HullUtil.hull(points).scale(radius*(phi-1)).getPolygons();
92 
93  return polygons;
94  }
95 
101  public Vector3d getCenter() {
102  return center;
103  }
104 
111  this.center = center;
112  return this;
113  }
114 
120  public double getRadius() {
121  return radius;
122  }
123 
129  public void setRadius(double radius) {
130  this.radius = radius;
131  }
132 
133  /* (non-Javadoc)
134  * @see eu.mihosoft.vrl.v3d.Primitive#getProperties()
135  */
136  @Override
138  return properties;
139  }
140 
146  centered = false;
147  return this;
148  }
149 
150 }
List< Polygon > getPolygons()
Definition: CSG.java:698
CSG scale(Number scaleValue)
Definition: CSG.java:611
Dodecahedron setCenter(Vector3d center)
final PropertyStorage properties
Dodecahedron(Vector3d center, double size)