Skip to content

Commit 147eeb0

Browse files
committed
Adding additional primatives
1 parent 28979c2 commit 147eeb0

File tree

2 files changed

+291
-0
lines changed

2 files changed

+291
-0
lines changed
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
/**
2+
* Dodecahedron.java
3+
*/
4+
package eu.mihosoft.jcsg;
5+
6+
import java.util.ArrayList;
7+
import java.util.List;
8+
9+
import eu.mihosoft.jcsg.ext.quickhull3d.HullUtil;
10+
import eu.mihosoft.vvecmath.Vector3d;
11+
12+
13+
public class Dodecahedron implements Primitive {
14+
15+
/**
16+
* Center of this dodecahedron.
17+
*/
18+
private Vector3d center;
19+
/**
20+
* Dodecahedron circumscribed radius.
21+
*/
22+
private double radius;
23+
24+
/** The centered. */
25+
private boolean centered = true;
26+
27+
/** The properties. */
28+
private final PropertyStorage properties = new PropertyStorage();
29+
/**
30+
* Constructor. Creates a new dodecahedron with center {@code [0,0,0]} and
31+
* dimensions {@code [1,1,1]}.
32+
*/
33+
public Dodecahedron() {
34+
center = Vector3d.xyz(0, 0, 0);
35+
radius = 1;
36+
}
37+
38+
/**
39+
* Constructor. Creates a new dodecahedron with center {@code [0,0,0]} and
40+
* radius {@code size}.
41+
*
42+
* @param size size
43+
*/
44+
public Dodecahedron(double size) {
45+
center = Vector3d.xyz(0, 0, 0);
46+
radius = size;
47+
}
48+
49+
/**
50+
* Constructor. Creates a new dodecahedron with the specified center and
51+
* radius.
52+
*
53+
* @param center center of the dodecahedron
54+
* @param circumradius of the dodecahedron
55+
*/
56+
public Dodecahedron(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+
67+
double phi = (Math.sqrt(5)+1)/2;
68+
69+
List<Vector3d> points = new ArrayList<>();
70+
points.add(Vector3d.xyz(-1,-1,-1));
71+
points.add(Vector3d.xyz(-1,-1,+1));
72+
points.add(Vector3d.xyz(-1,+1,-1));
73+
points.add(Vector3d.xyz(-1,+1,+1));
74+
points.add(Vector3d.xyz(+1,-1,-1));
75+
points.add(Vector3d.xyz(+1,-1,+1));
76+
points.add(Vector3d.xyz(+1,+1,-1));
77+
points.add(Vector3d.xyz(+1,+1,+1));
78+
points.add(Vector3d.xyz(0,1/phi,phi));
79+
points.add(Vector3d.xyz(0,-1/phi,phi));
80+
points.add(Vector3d.xyz(phi,0,1/phi));
81+
points.add(Vector3d.xyz(1/phi,phi,0));
82+
points.add(Vector3d.xyz(-1/phi,phi,0));
83+
points.add(Vector3d.xyz(-phi,0,1/phi));
84+
points.add(Vector3d.xyz(1/phi,-phi,0));
85+
points.add(Vector3d.xyz(phi,0,-1/phi));
86+
points.add(Vector3d.xyz(0,1/phi,-phi));
87+
points.add(Vector3d.xyz(-phi,0,-1/phi));
88+
points.add(Vector3d.xyz(-1/phi,-phi,0));
89+
points.add(Vector3d.xyz(0,-1/phi,-phi));
90+
91+
List<Polygon> polygons = HullUtil.hull(points).scale(radius*(phi-1)).getPolygons();
92+
93+
return polygons;
94+
}
95+
96+
/**
97+
* Gets the center.
98+
*
99+
* @return the center
100+
*/
101+
public Vector3d getCenter() {
102+
return center;
103+
}
104+
105+
/**
106+
* Sets the center.
107+
*
108+
* @param center the center to set
109+
*/
110+
public Dodecahedron setCenter(Vector3d center) {
111+
this.center = center;
112+
return this;
113+
}
114+
115+
/**
116+
* Gets the radius.
117+
*
118+
* @return the radius
119+
*/
120+
public double getRadius() {
121+
return radius;
122+
}
123+
124+
/**
125+
* Sets the radius.
126+
*
127+
* @param radius the radius to set
128+
*/
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
137+
public PropertyStorage getProperties() {
138+
return properties;
139+
}
140+
141+
/**
142+
* Defines that this dodecahedron will not be centered.
143+
* @return this dodecahedron
144+
*/
145+
public Dodecahedron noCenter() {
146+
centered = false;
147+
return this;
148+
}
149+
150+
}
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
/**
2+
* Icosahedron.java
3+
*/
4+
package eu.mihosoft.jcsg;
5+
6+
import java.util.ArrayList;
7+
import java.util.List;
8+
9+
import eu.mihosoft.jcsg.ext.quickhull3d.HullUtil;
10+
import eu.mihosoft.vvecmath.Vector3d;
11+
12+
public class Icosahedron implements Primitive {
13+
14+
/**
15+
* Center of this icosahedron.
16+
*/
17+
private Vector3d center;
18+
/**
19+
* Icosahedron circumscribed radius.
20+
*/
21+
private double radius;
22+
23+
/** The centered. */
24+
private boolean centered = true;
25+
26+
/** The properties. */
27+
private final PropertyStorage properties = new PropertyStorage();
28+
/**
29+
* Constructor. Creates a new icosahedron with center {@code [0,0,0]} and
30+
* dimensions {@code [1,1,1]}.
31+
*/
32+
public Icosahedron() {
33+
center = Vector3d.xyz(0, 0, 0);
34+
radius = 1;
35+
}
36+
37+
/**
38+
* Constructor. Creates a new icosahedron with center {@code [0,0,0]} and
39+
* radius {@code size}.
40+
*
41+
* @param size size
42+
*/
43+
public Icosahedron(double size) {
44+
center = Vector3d.xyz(0, 0, 0);
45+
radius = size;
46+
}
47+
48+
/**
49+
* Constructor. Creates a new icosahedron with the specified center and
50+
* radius.
51+
*
52+
* @param center center of the icosahedron
53+
* @param circumradius of the icosahedron
54+
*/
55+
public Icosahedron(Vector3d center, double size) {
56+
this.center = center;
57+
this.radius = size;
58+
}
59+
60+
/* (non-Javadoc)
61+
* @see eu.mihosoft.vrl.v3d.Primitive#toPolygons()
62+
*/
63+
@Override
64+
public List<Polygon> toPolygons() {
65+
66+
double phi = (Math.sqrt(5)+1)/2;
67+
68+
List<Vector3d> points = new ArrayList<>();
69+
points.add(Vector3d.xyz(0,1,phi));
70+
points.add(Vector3d.xyz(0,-1,phi));
71+
points.add(Vector3d.xyz(phi,0,1));
72+
points.add(Vector3d.xyz(1,phi,0));
73+
points.add(Vector3d.xyz(-1,phi,0));
74+
points.add(Vector3d.xyz(-phi,0,1));
75+
points.add(Vector3d.xyz(1,-phi,0));
76+
points.add(Vector3d.xyz(phi,0,-1));
77+
points.add(Vector3d.xyz(0,1,-phi));
78+
points.add(Vector3d.xyz(-phi,0,-1));
79+
points.add(Vector3d.xyz(-1,-phi,0));
80+
points.add(Vector3d.xyz(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+
87+
/**
88+
* Gets the center.
89+
*
90+
* @return the center
91+
*/
92+
public Vector3d getCenter() {
93+
return center;
94+
}
95+
96+
/**
97+
* Sets the center.
98+
*
99+
* @param center the center to set
100+
*/
101+
public Icosahedron setCenter(Vector3d center) {
102+
this.center = center;
103+
return this;
104+
}
105+
106+
/**
107+
* Gets the radius.
108+
*
109+
* @return the radius
110+
*/
111+
public double getRadius() {
112+
return radius;
113+
}
114+
115+
/**
116+
* Sets the radius.
117+
*
118+
* @param radius the radius to set
119+
*/
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
128+
public PropertyStorage getProperties() {
129+
return properties;
130+
}
131+
132+
/**
133+
* Defines that this icosahedron will not be centered.
134+
* @return this icosahedron
135+
*/
136+
public Icosahedron noCenter() {
137+
centered = false;
138+
return this;
139+
}
140+
141+
}

0 commit comments

Comments
 (0)