JavaCAD
Octahedron.java
Go to the documentation of this file.
1 /*
2  * Octahedron.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 Octahedron extends Primitive {
12 
16  private Vector3d center;
20  private double radius;
21 
23  private boolean centered = true;
24 
31  public Octahedron() {
32  center = new Vector3d(0, 0, 0);
33  radius = 1;
34  }
35 
42  public Octahedron(double size) {
43  center = new Vector3d(0, 0, 0);
44  radius = size;
45  }
46 
54  public Octahedron(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 sqrt2_2 = Math.sqrt(2)/2;
67 
68  List<Vector3d> points = new ArrayList<>();
69  points.add(new Vector3d(0,0,-1));
70  points.add(new Vector3d(0,0,+1));
71  points.add(new Vector3d(-sqrt2_2,-sqrt2_2,0));
72  points.add(new Vector3d(-sqrt2_2,+sqrt2_2,0));
73  points.add(new Vector3d(+sqrt2_2,-sqrt2_2,0));
74  points.add(new Vector3d(+sqrt2_2,+sqrt2_2,0));
75 
76  List<Polygon> polygons = HullUtil.hull(points).scale(radius).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 
130  public Octahedron noCenter() {
131  centered = false;
132  return this;
133  }
134 
135 }
List< Polygon > getPolygons()
Definition: CSG.java:698
CSG scale(Number scaleValue)
Definition: CSG.java:611
PropertyStorage getProperties()
void setRadius(double radius)
List< Polygon > toPolygons()
Definition: Octahedron.java:63
Octahedron(Vector3d center, double size)
Definition: Octahedron.java:54
final PropertyStorage properties
Definition: Octahedron.java:26
Octahedron setCenter(Vector3d center)
Definition: Octahedron.java:95