JavaCAD
Icosahedron.java
Go to the documentation of this file.
1 /*
2  * Icosahedron.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 
11 public class Icosahedron extends Primitive {
12 
16  private Vector3d center;
20  private double radius;
21 
23  private boolean centered = true;
24 
31  public Icosahedron() {
32  center = new Vector3d(0, 0, 0);
33  radius = 1;
34  }
35 
42  public Icosahedron(double size) {
43  center = new Vector3d(0, 0, 0);
44  radius = size;
45  }
46 
54  public Icosahedron(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  double phi = (Math.sqrt(5)+1)/2;
67 
68  List<Vector3d> points = new ArrayList<>();
69  points.add(new Vector3d(0,1,phi));
70  points.add(new Vector3d(0,-1,phi));
71  points.add(new Vector3d(phi,0,1));
72  points.add(new Vector3d(1,phi,0));
73  points.add(new Vector3d(-1,phi,0));
74  points.add(new Vector3d(-phi,0,1));
75  points.add(new Vector3d(1,-phi,0));
76  points.add(new Vector3d(phi,0,-1));
77  points.add(new Vector3d(0,1,-phi));
78  points.add(new Vector3d(-phi,0,-1));
79  points.add(new Vector3d(-1,-phi,0));
80  points.add(new Vector3d(0,-1,-phi));
81 
82  List<Polygon> polygons = HullUtil.hull(points).scale(radius/(Math.sqrt(1+Math.pow(phi, 2)))).getPolygons();
83 
84  return polygons;
85  }
86 
92  public Vector3d getCenter() {
93  return center;
94  }
95 
102  this.center = center;
103  return this;
104  }
105 
111  public double getRadius() {
112  return radius;
113  }
114 
120  public void setRadius(double radius) {
121  this.radius = radius;
122  }
123 
124  /* (non-Javadoc)
125  * @see eu.mihosoft.vrl.v3d.Primitive#getProperties()
126  */
127  @Override
129  return properties;
130  }
131 
137  centered = false;
138  return this;
139  }
140 
141 }
List< Polygon > getPolygons()
Definition: CSG.java:698
CSG scale(Number scaleValue)
Definition: CSG.java:611
Icosahedron setCenter(Vector3d center)
void setRadius(double radius)
Icosahedron(Vector3d center, double size)
final PropertyStorage properties