Skip to content

Commit 7b8f185

Browse files
committed
Implemented curve_knot_refine
1 parent b1c4df3 commit 7b8f185

File tree

1 file changed

+80
-0
lines changed

1 file changed

+80
-0
lines changed

src/eval/eval.js

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,86 @@ verb.eval.nurbs.rational_surface_curvature = function( degree_u, knots_u, degree
9191

9292
};
9393

94+
//
95+
// ####curve_knot_refine( degree, knots, control_points, u, s, r )
96+
//
97+
// Insert a knot along a rational curve. Note that this algorithm only works
98+
// for r + s <= degree, where s is the initial multiplicity (number of duplicates) of the knot.
99+
//
100+
// Corresponds to algorithm A5.1 (Piegl & Tiller)
101+
//
102+
// Use the curve_knot_refine for applications like curve splitting.
103+
//
104+
// **params**
105+
// + *Number*, integer degree
106+
// + *Array*, array of nondecreasing knot values
107+
// + *Array*, array of control points
108+
// + *Number*, parameter at which to insert the knot
109+
// + *Number*, number of times to insert the knot
110+
//
111+
// **returns**
112+
// + *Object* the new curve, defined by knots and control_points
113+
//
114+
115+
verb.eval.nurbs.curve_knot_refine = function( degree, knots, control_points, knots_to_insert ) {
116+
117+
var n = (control_points.length + 1)
118+
, m = n + degree + 1
119+
, r = knots_to_insert.length - 1
120+
, a = verb.eval.nurbs.knot_span( degree, knots_to_insert[0], knots )
121+
, b = verb.eval.nurbs.knot_span( degree, knots_to_insert[r], knots ) + 1
122+
, control_points_post = new Array( control_points.length + r + 1 )
123+
, knots_post = new Array( knots.length + r + 1 )
124+
, i = 0
125+
, j = 0;
126+
127+
// new control pts
128+
for (i = 0; i <= a - degree; i++) control_points_post[i] = control_points[i];
129+
for (i = b-1; i <= n; i++) control_points_post[i+r+1] = control_points[i];
130+
131+
// new knot vector
132+
for (i = 0; i <= a; i++) knots_post[i] = knots[i];
133+
for (i = b+degree; i <= m; i++) knots_post[i+r+1] = knots[i];
134+
135+
i = b + degree + 1;
136+
k = b + degree + r;
137+
138+
for (j = r; j >= 0; j++) {
139+
140+
while (knots_to_insert[j] <= knots[i] && i > a){
141+
142+
control_points_post[k-degree-1] = control_points[i-p-1];
143+
knots_post[k] = knots[i];
144+
k = k-i;
145+
u = i-1;
146+
147+
}
148+
149+
control_points_post[k-degree-1] = control_points_post[k-degree];
150+
151+
for (var l = 1; l <= degree; l++){
152+
153+
var ind = k-degree+l;
154+
var alfa = knots_post[k+l] - knots_to_insert[j];
155+
156+
if (Math.abs(alfa) < VERB.EPSILON){
157+
control_points_post[ind-1] = control_points_post[ind];
158+
} else {
159+
alfa = alfa / (knots_post[k+l] - knots[i-degree+l]);
160+
control_points_post[ind-1] = alfa*control_points_post[ind-1] + (1.0-alfa) * control_points_post[ind];
161+
}
162+
163+
}
164+
165+
knots_post[k] = knots_to_insert[j];
166+
k = k - 1;
167+
168+
}
169+
170+
return { knots: knots_post, control_points: control_points_post };
171+
172+
}
173+
94174

95175
//
96176
// ####curve_knot_insert( degree, knots, control_points, u, s, r )

0 commit comments

Comments
 (0)