-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathAbstractBezierBoardSurfaceModel.java
172 lines (133 loc) · 4.36 KB
/
AbstractBezierBoardSurfaceModel.java
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
package cadcore;
import javax.vecmath.Point3d;
import javax.vecmath.Vector3d;
import board.BezierBoard;
abstract public class AbstractBezierBoardSurfaceModel
{
//LinearInterpolation is obsolete, keep for reference
public enum ModelType{LinearInterpolation, ControlPointInterpolation, SLinearInterpolation};
static public AbstractBezierBoardSurfaceModel getBezierBoardSurfaceModel(ModelType modelType)
{
switch(modelType)
{
default:
case ControlPointInterpolation:
return new BezierBoardControlPointInterpolationSurfaceModel();
case SLinearInterpolation:
return new BezierBoardSLinearInterpolationSurfaceModel();
}
}
public abstract Point3d getDeckAt(final BezierBoard brd, final double x, final double y);
public Vector3d getDeckNormalAt(final BezierBoard brd, final double x, final double y)
{
final double OFFSET = 0.01;
boolean flipNormal = false;
double xo = x-OFFSET;
if(xo < 0)
{
xo = x+OFFSET;
flipNormal = !flipNormal;
}
double yo = y-OFFSET;
if(yo < 0)
{
yo = y+OFFSET;
flipNormal = !flipNormal;
}
Point3d p1 = getDeckAt(brd,x,y);
Point3d p2 = getDeckAt(brd,x,yo);
Vector3d pv = new Vector3d(0, y-yo, p2.z-p1.z);
Point3d p3 = getDeckAt(brd,xo,y);
Vector3d lv = new Vector3d(x-xo, 0, p3.z-p1.z);
Vector3d normalVec = new Vector3d();
normalVec.cross(pv,lv);
normalVec.normalize();
if(flipNormal)
{
normalVec.scale(-1.0);
}
return normalVec;
}
public abstract Point3d getBottomAt(final BezierBoard brd, final double x, final double y);
public Vector3d getBottomNormalAt(final BezierBoard brd, final double x, final double y)
{
final double OFFSET = 0.01;
boolean flipNormal = false;
double xo = x-OFFSET;
if(xo < 0)
{
xo = x+OFFSET;
flipNormal = !flipNormal;
}
double yo = y-OFFSET;
if(yo < 0)
{
yo = y+OFFSET;
flipNormal = !flipNormal;
}
Point3d p1 = getBottomAt(brd,x,y);
Point3d p2 = getBottomAt(brd,x,yo);
Point3d p3 = getBottomAt(brd,xo,y);
Vector3d pv = new Vector3d(0, y-yo, p2.z-p1.z);
Vector3d lv = new Vector3d(x-xo, 0, p3.z-p1.z);
Vector3d normalVec = new Vector3d();
normalVec.cross(pv,lv);
normalVec.normalize();
if(flipNormal)
{
normalVec.scale(-1.0);
}
return normalVec;
}
public abstract Point3d getPointAt(final BezierBoard brd, double x, double s, double minAngle, double maxAngle, boolean useMinimumAngleOnSharpCorners);
public Vector3d getNormalAt(final BezierBoard brd, double x, double s, double minAngle, double maxAngle, boolean useMinimumAngleOnSharpCorners)
{
final double X_OFFSET = 0.1;
final double S_OFFSET = 0.01;
boolean flipNormal = false;
double so = s+S_OFFSET;
if(so > 1.0)
{
so = s-S_OFFSET;
flipNormal = true;
}
if(x < 1.0)
{
x = .0;
}
if(x > brd.getLength() - 1.0)
{
x = brd.getLength() - 1.0;
}
double xo = x+X_OFFSET;
Point3d p = getPointAt(brd, x,s,minAngle,maxAngle, useMinimumAngleOnSharpCorners);
Point3d pso = getPointAt(brd, x,so,minAngle,maxAngle, useMinimumAngleOnSharpCorners);
Point3d pxo = getPointAt(brd, xo,s,minAngle,maxAngle, useMinimumAngleOnSharpCorners);
Vector3d vc = new Vector3d(0, p.y-pso.y, p.z-pso.z); //Vector across
vc.normalize();
Vector3d vl = new Vector3d(pxo.x-p.x, pxo.y-p.y, pxo.z-p.z); //Vector lengthwise
vl.normalize();
Vector3d normalVec = new Vector3d();
normalVec.cross(vc,vl);
normalVec.normalize();
if(flipNormal == true)
{
normalVec.scale(-1.0);
}
/*DEBUG
if(cv.angle(lv)*180.0/Math.PI < 15)
{
System.out.printf("getSurfaceNormalAtPos() Low angle between vectors: %f\n", cv.angle(lv)*180.0/Math.PI);
}
if(last != null && last.angle(normalVec)*180.0/Math.PI > 15)
{
System.out.printf("getSurfaceNormalAtPos() large angle between last and current normal:%f\n", last.angle(normalVec)*180.0/Math.PI);
}
last = new Vector3d(normalVec);
// System.out.printf("getNormalAtPos() x:%f, xo:%f, sa:%f, sao:%f, sb:%f, sbo:%f\n", x, xo, sa, sao, sb, sbo);
// System.out.printf("getNormalAtPos() %f, %f, %f\n", normalVec.x,normalVec.y,normalVec.z);
*/
return normalVec;
}
public abstract double getCrosssectionAreaAt(final BezierBoard brd,double x, int splits);
}