-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMisc.prejava
More file actions
152 lines (142 loc) · 5.79 KB
/
Misc.prejava
File metadata and controls
152 lines (142 loc) · 5.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#include "macros.h"
// TODO: what is this file? is it used anywhere??
import com.donhatchsw.util.CSG;
import com.donhatchsw.util.VecMath;
import com.donhatchsw.compat.Format;
final public class Misc
{
private Misc(){ throw new AssertionError(); } // non-instantiatable util class
// Assumes sp is platonic
public static double circumconeCurvature(CSG.SPolytope sp)
{
// Take the angle between vertex-to-cell-center
// and same-vertex-to-edge-center.
CHECK_EQ(sp.p.dim, 3);
CSG.SPolytope face = sp.p.facets[0];
CSG.SPolytope edge = face.p.facets[0];
CSG.SPolytope vertex = edge.p.facets[0];
double cellCenter[] = CSG.cgOfVerts(sp.p);
double faceCenter[] = CSG.cgOfVerts(face.p);
double edgeCenter[] = CSG.cgOfVerts(edge.p);
double vertexCenter[] = CSG.cgOfVerts(vertex.p);
double angle = VecMath.angleBetweenUnitVectors(
VecMath.normalize(VecMath.vmv(cellCenter,vertexCenter)),
VecMath.normalize(VecMath.vmv(edgeCenter,vertexCenter)));
double frac = Math.sin(angle);
return 2*Math.PI*(1-frac);
}
// Assumes sp is platonic
public static double vertexCurvature(CSG.SPolytope sp)
{
// Take a vertex.
// Add up all the interior angles of faces at that vertex.
// Subtract the result from 2*pi.
CSG.SPolytope face = sp.p.facets[0];
CSG.SPolytope edge = face.p.facets[0];
CSG.SPolytope vertex = edge.p.facets[0];
double cellCenter[] = CSG.cgOfVerts(sp.p);
double faceCenter[] = CSG.cgOfVerts(face.p);
double edgeCenter[] = CSG.cgOfVerts(edge.p);
double vertexCenter[] = CSG.cgOfVerts(vertex.p);
double angle = VecMath.angleBetweenUnitVectors(
VecMath.normalize(VecMath.vmv(faceCenter,vertexCenter)),
VecMath.normalize(VecMath.vmv(edgeCenter,vertexCenter)));
int vertexValence = sp.p.getAllIncidences()[0][0][1].length;
return 2*Math.PI - vertexValence*2*angle;
}
// Assumes sp is platonic
public static double inconeCurvature(CSG.SPolytope sp)
{
// Take the angle between vertex-to-cell-center
// and same-vertex-to-face-center.
CHECK_EQ(sp.p.dim, 3);
CSG.SPolytope face = sp.p.facets[0];
CSG.SPolytope edge = face.p.facets[0];
CSG.SPolytope vertex = edge.p.facets[0];
double cellCenter[] = CSG.cgOfVerts(sp.p);
double faceCenter[] = CSG.cgOfVerts(face.p);
double edgeCenter[] = CSG.cgOfVerts(edge.p);
double vertexCenter[] = CSG.cgOfVerts(vertex.p);
double angle = VecMath.angleBetweenUnitVectors(
VecMath.normalize(VecMath.vmv(cellCenter,vertexCenter)),
VecMath.normalize(VecMath.vmv(faceCenter,vertexCenter)));
double frac = Math.sin(angle);
return 2*Math.PI*(1-frac);
}
public static double circumconeCurvature(double p, double q)
{
//double angle = Math.asin(Math.sin(Math.PI/2*(p-2)/p)/Math.sin(Math.PI/q));
//double frac = Math.sin(angle);
double frac = Math.sin(Math.PI/2*(p-2)/p)/Math.sin(Math.PI/q);
return 2*Math.PI*(1-frac);
}
public static double vertexCurvature(double p, double q)
{
return 2*Math.PI - q*(Math.PI*(p-2)/p);
}
public static double inconeCurvature(double p, double q)
{
//double angle = Math.asin(Math.tan(Math.PI/2*(p-2)/p)/Math.tan(Math.PI/q));
//double frac = Math.sin(angle);
double frac = Math.tan(Math.PI/2*(p-2)/p)/Math.tan(Math.PI/q);
return 2*Math.PI*(1-frac);
}
public static void printPlatonicSolidVertexCurvatures()
{
{
int schlaflis[][] = {
{3,3},
{4,3},
{3,4},
{5,3},
{3,5},
};
FORI (i, schlaflis.length)
{
int schlafli[] = schlaflis[i];
CSG.SPolytope sp = CSG.makeRegularPolytope(schlafli);
System.out.println(" {"+schlafli[0]+","+schlafli[1]+"}"
+" circumcone curvature = "+Format.sprintf("%.17g", RTOD(circumconeCurvature(sp)))
+" vertex curvature = "+Format.sprintf("%.17g", RTOD(vertexCurvature(sp)))
+" incone curvature = "+Format.sprintf("%.17g", RTOD(inconeCurvature(sp)))+"");
}
System.out.println();
}
{
double schlaflis[][] = {
{3,3},
{4,3},
{3,4},
{5,3},
{3,5},
{5.5,3},
{5.9,3},
{5.99,3},
{5.999,3},
{5.9999,3},
{5.99999,3},
{5.999999,3},
{5.9999999,3},
{5.99999999,3},
{5.999999999,3},
{5.9999999999,3},
{5.99999999999,3},
};
FORI (i, schlaflis.length)
{
double schlafli[] = schlaflis[i];
double p = schlafli[0];
double q = schlafli[1];
System.out.println(" {"+p+","+q+"}"
+" circumcone curvature = "+Format.sprintf("%.17g", RTOD(circumconeCurvature(p,q)))
+" vertex curvature = "+Format.sprintf("%.17g", RTOD(vertexCurvature(p,q)))
+" incone curvature = "+Format.sprintf("%.17g", RTOD(inconeCurvature(p,q)))+"");
}
System.out.println();
}
} // printPlatonicSolidVertexCurvatures
public static void main(String args[])
{
printPlatonicSolidVertexCurvatures();
}
} // class Misc