-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathBSplineCurve.html
executable file
·834 lines (645 loc) · 41.1 KB
/
BSplineCurve.html
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
<!DOCTYPE html><html xmlns:dc="http://purl.org/dc/terms/"><head><meta http-equiv=Content-Type content="text/html; charset=utf-8"><meta name="viewport" content="width=device-width"><link rel=stylesheet type="text/css" href="/style.css">
<script type="text/x-mathjax-config"> MathJax.Hub.Config({"HTML-CSS": { availableFonts: ["STIX","TeX"], linebreaks: { automatic:true }, preferredFont: "TeX" },
tex2jax: { displayMath: [ ["$$","$$"], ["\\[", "\\]"] ], inlineMath: [ ["$", "$"], ["\\\\(","\\\\)"] ], processEscapes: true } });
</script><script type="text/javascript" async src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS_HTML-full"></script></head><body> <div class="header">
<nav><p><a href="#navigation">Menu</a> - <a href="#top">Top</a> - <a href="/">Home</a></nav></div>
<div class="mainarea" id="top">
<h1 id="bsplinecurve">BSplineCurve</h1>
<p><a href="index.html">Back to documentation index.</a></p>
<p><a name="BSplineCurve"></a>
### new BSplineCurve(controlPoints, knots, [bits])</p>
<p><strong>Augments:</strong> <a href="Curve.html">Curve</a></p>
<p>A <a href="Curve.html">curve evaluator object</a> for a B-spline (basis spline) curve.
A B-spline curve is a parametric curve based on polynomial functions.
Each polynomial is generated using one or more
<i>control points</i>, which more or less follow the path of the curve,
and a <i>knot vector</i>, which determines, more or less, where each control
point is spaced along the curve. Together with rational B-spline curves (see
later), this makes B-spline curves very powerful,
since they can describe nearly all curves commonly used in computer
graphics, including line segments, circles, ellipses, parabolas, and
irregular smooth curves. With the B-spline curves supported here, a perspective transformation (including a rotation, translation, or scaling) of the curve’s control points leads to the same transformation of the resulting curve.</p>
<p><b>Bézier Curves</b></p>
<p>A Bézier curve is defined by a series of control points, where
the first and last control points are the curve’s end points, and
the remaining control points define the curve’s shape, though they don’t
necessarily cross the curve. An important property of these curves is
that the bounding box of the curve is contained within the bounding box
of the control points. Another important property is that the starting direction
is the same as the direction from the
first to the second control point, and the ending direction is the same as the
direction from the next-to-last to last control point.</p>
<p>Bézier curves are a subset of B-spline curves
(see <a href="BSplineCurve.html#BSplineCurve.fromBezierCurve">BSplineCurve.fromBezierCurve</a>).</p>
<p>Line segments are degree-1 Bézier curves with two control points.</p>
<p>A Bézier curve’s knot vector consists of as many zeros as the number
of control points, followed by that many ones. For example, a degree-3 (cubic)
Bézier curve contains four control points and the following knot vector:
<code>[0, 0, 0, 0, 1, 1, 1, 1]</code>.</p>
<p><b>Non-Uniform Curves</b></p>
<p>A nonuniform B-spline curve is one whose knot vector is not evenly spaced,
that is, the difference between one knot and the next isn’t the same.</p>
<p><b>Rational Curves</b></p>
<p>A rational B-spline curve is an N-dimensional curve with N plus one coordinates
per control point (<i>homogeneous coordinates</i>). B-spline algorithms
work the same way with homogeneous coordinates as with conventional
coordinates, but if N-dimensional points are wanted, use the <a href="BSplineCurve.html#BSplineCurve.DIVIDE_BIT">BSplineCurve.DIVIDE_BIT</a>
flag to divide each coordinate by the last (and omit the last coordinate)
to convert to N-dimensional points.</p>
<p>Rational B-spline curves can describe circles and ellipses, which nonrational B-spline curves can’t.</p>
<p>Note that some B-spline packages define rational B-spline curves as using control points and weights, that is,
N-dimensional control points in conventional coordinates, along with a separate number, or <i>weight</i>,
for each control point. To convert such a control point to homogeneous coordinates, multiply each of its
conventional coordinates by its weight, then append the weight as the control point’s last coordinate.</p>
<p><b>NURBS Curves</b></p>
<p><i>NURBS</i> is an acronym for nonuniform rational B-spline curves.</p>
<p><b>Polynomial Basis</b></p>
<p>Any kind of polynomial curve can be converted to a different kind
of polynomial curve, having the same degree and describing the same path,
by transforming its control points. For example, a Hermite curve (another
kind of polynomial curve) can be converted to the equivalent
B-spline curve this way, or vice versa.</p>
<p>Each kind of polynomial curve (such as B-spline or Bézier) is
associated with a <i>basis matrix</i>, which defines the polynomial
coefficients for each control point in the curve. For a degree (N-1) curve,
the matrix will be N×N.</p>
<p>Each “column” of a basis matrix is a polynomial
containing the coefficients for each control point, and the columns are
arranged from left to right. Each polynomial consists of coefficients, ranging from the
highest order to the lowest, with respect to the parameter
<code>t</code> and the corresponding control point. For example, the
column <code>(3, 4, 2, 10)</code> describes the polynomial
3xt<sup>3</sup> + 4xt<sup>2</sup> + 2xt + 10x, where <code>x</code>
is the input control point. The polynomials
are added together to get the final coordinate of the curve at the specified <code>t</code> value.</p>
<p>The following JavaScript code shows an example of a basis matrix – the
cubic Bézier basis matrix.<br /></p>
<pre>var bezierBasisMatrix = [
// For the purposes of the Math matrix functions,
// the polynomials are arranged "column-wise", like this:
// P1, P2, P3, P4
-1,3,-3,1,
3,-6,3,0,
-3,3,0,0,
1,0,0,0]
</pre>
<p>For code that converts a curve from one kind to
another, see the example.</p>
<h4 id="parameters">Parameters</h4>
<ul>
<li><code>controlPoints</code> (Type: Array.<Array.<number»)<br />An array of control points. Each control point is an array with the same length as the other control points. It is assumed that the first control point’s length represents the size of all the control points.</li>
<li><code>knots</code> (Type: Array.<number>)<br />Knot vector of the curve. Its size must be at least 2 plus the number of control points and not more than twice the number of control points.<br /> The length of this parameter minus 1, minus the number of control points, represents the <i>degree</i> of the B-spline curve. For example, a degree-3 (cubic) B-spline curve with four control points must contain eight knots, which is four (1 plus degree 3) more knots than the number of control points. A degree of 1 results in straight line segments.<br /> The knot vector must be a nowhere increasing sequence, the first knot must not equal the last, and the same knot may not be repeated more than N+1 times at the beginning and end of the vector, or more than N times elsewhere, where N is the curve’s degree. If the difference between one knot and the next isn’t the same, the curve is considered a <i>nonuniform</i> B-spline curve. Usually the first knot will be 0 or less and the last knot will be 1 or greater. (Note that this class uses the definition of knot vectors given by <a href="https://pages.mtu.edu/~shene/COURSES/cs3621/NOTES/spline/B-spline/bspline-curve.html">C.-K. Shene</a>. There are computer-aided design programs that use knot vectors in which the first and last knot are omitted; they can be converted to Shene’s definition by repeating the first knot at the beginning and repeating the last knot at the end.)</li>
<li><code>bits</code> (Type: number) (optional)<br />Bits for defining input and controlling output. Zero or more of <a href="BSplineCurve.html#BSplineCurve.DIVIDE_BIT">BSplineCurve.DIVIDE_BIT</a>. If null, undefined, or omitted, no bits are set.</li>
</ul>
<h4 id="examples">Examples</h4>
<p>The following function can be used
to convert an array of control points, each consisting of conventional
coordinates and a weight, to homogeneous coordinates.
For example, the single-control point
‘[[2, 3, 4, 0.1]]’ becomes ‘[[0.2, 0.3, 0.4, 0.1]]’; the
return value can then be used in the BSplineCurve constructor
to create a rational B-Spline curve.</p>
<pre>function convertToHomogen(cp) {
var ret = [];
var cplen = cp[0].length;
for(var i = 0; i < cp.length; i++) {
var outp = [];
var w = cp[i][cplen - 1];
for(var j = 0; j < cplen - 1; j++) {
outp[j] = cp[i][j] * w;
}
outp[cplen - 1] = w;
ret.push(outp);
}
return ret;
};
</pre>
<p>The following code converts a cubic (degree-3)
curve from one kind to another. The converted curve will generally
have the same path as the original curve.</p>
<pre>// "srcBasis" is a 4 &times; 4 basis matrix for the source curve type;
// the control points will initially be of this type of curve.
// var srcBasis = [ .... ]; // To be supplied or filled in.
// "dstBasis" is a 4 &times; 4 basis matrix for the destination curve type.
// It's defined here as the B&eacute;zier basis matrix for this example
var dstBasis =[-1,3,-3,1, 3,-6,3,0, -3,3,0,0, 1,0,0,0];
// Step 1: Invert the destination basis matrix
var invertedDest=MathUtil.mat4invert(destBasis)
// Step 2: Multiply the inverted destination matrix by the source
// matrix
var resultMatrix=MathUtil.mat4multiply(invertedDest,srcBasis)
// Step 3: Convert the control points one dimension
// at a time
var newControlPoints=[[],[],[],[]]
for(var i=0;i < controlPoints[0].length;i++) {
var cp=[controlPoints[0][i],controlPoints[1][i],controlPoints[2][i],
controlPoints[3][i]]
// Transform the control points using the result matrix
cp=MathUtil.vec4transform(resultMatrix,cp)
// Set the new coordinates
newControlPoints[0][i]=cp[0]
newControlPoints[1][i]=cp[1]
newControlPoints[2][i]=cp[2]
newControlPoints[3][i]=cp[3]
}
// Finally, generate a B&eacute;zier curve (which is a special case
// of a B-spline curve)
var curve=new BSplineCurve(
newControlPoints,
[0,0,0,0,1,1,1,1] // cubic B&eacute;zier knot vector
);
// Alternatively, the curve could be generated with the
// fromBezierCurve method:
// var curve=BSplineCurve.fromBezierCurve(newControlPoints);
</pre>
<h3 id="members">Members</h3>
<ul>
<li><a href="#BSplineCurve.DIVIDE_BIT">DIVIDE_BIT</a><br />Indicates to divide each other coordinate of the returned point
by the last coordinate of the point and omit the last
coordinate.</li>
</ul>
<h3 id="methods">Methods</h3>
<ul>
<li><a href="#BSplineCurve_accel">accel</a><br />Finds an approximate acceleration vector at the specified u-coordinate of this curve.</li>
<li><a href="#BSplineCurve_arcLength">arcLength</a><br />Finds an approximate arc length (distance) between the start of this
curve and the point at the specified u-coordinate of this curve.</li>
<li><a href="#BSplineCurve_changeEnds">changeEnds</a><br />Creates a curve evaluator object for a curve that is generated using
the same formula as this one (and uses the same u-coordinates),
but has a different set of end points.</li>
<li><a href="#BSplineCurve.clamped">clamped</a><br />Creates a B-spline curve with uniform knots, except that
the curve will start and end at the first and last control points and will
be tangent to the line between the first and second control points
and to the line between the next-to-last and last control points.</li>
<li><a href="#BSplineCurve.clampedKnots">clampedKnots</a><br />Generates a knot vector with uniform knots, to be
passed to the <a href="BSplineCurve.html">BSplineCurve</a> or <a href="BSplineSurface.html">BSplineSurface</a> constructor,
except that with the knot vector the curve will start and end at the first and last control points and will
be tangent to the line between the first and second control points
and to the line between the next-to-last and last control points.</li>
<li><a href="#BSplineCurve_endPoints">endPoints</a><br />Returns the starting and coordinates of this curve.</li>
<li><a href="#BSplineCurve_evaluate">evaluate</a><br />Evaluates the curve function based on a point
in a B-spline curve.</li>
<li><a href="#BSplineCurve_fitRange">fitRange</a><br />Creates a curve evaluator object for a curve that follows the same
path as this one but has its u-coordinates remapped to fit the specified range.</li>
<li><a href="#BSplineCurve.fromBezierCurve">fromBezierCurve</a><br />Creates a B-spline curve from the control points of a Bézier curve.</li>
<li><a href="#BSplineCurve.fromConicCurve">fromConicCurve</a><br />Creates a B-spline curve from the control points of a conic curve as described
in Apple TN1052, “QuickDraw GX ConicLibrary.c in Detail: Description and
Derivations”, 1996.</li>
<li><a href="#BSplineCurve_getControlPoints">getControlPoints</a><br />Gets a reference to the array of control points used
in this curve object.</li>
<li><a href="#BSplineCurve_getKnots">getKnots</a><br />Gets a reference to the array of knots used
in this curve object.</li>
<li><a href="#BSplineCurve_getLength">getLength</a><br />Convenience method for getting the total length of this curve.</li>
<li><a href="#BSplineCurve_getPoints">getPoints</a><br />Gets an array of positions on the curve at fixed intervals
of u-coordinates.</li>
<li><a href="#BSplineCurve_getPointsAsObjects">getPointsAsObjects</a><br />Gets an array of positions on the curve at fixed intervals
of u-coordinates.</li>
<li><a href="#BSplineCurve_jerk">jerk</a><br />Finds an approximate jerk vector at the specified u-coordinate of this curve.</li>
<li><a href="#BSplineCurve_normal">normal</a><br />Finds an approximate principal normal vector at the specified u-coordinate of this curve.</li>
<li><a href="#BSplineCurve_split">split</a><br />Splits this B-spline curve into two at the specified point.</li>
<li><a href="#BSplineCurve_tangent">tangent</a><br />Convenience method for finding an approximate tangent vector of this curve at the specified u-coordinate.</li>
<li><a href="#BSplineCurve_toArcLengthParam">toArcLengthParam</a><br />Gets a curve evaluator object for a curve that follows the same
path as this one but has its u-coordinates remapped to
an <i>arc length parameterization</i>.</li>
<li><a href="#BSplineCurve.uniform">uniform</a><br />Creates a B-spline curve with uniform knots.</li>
<li><a href="#BSplineCurve.uniformKnots">uniformKnots</a><br />Generates a knot vector with uniform knots, to be
passed to the <a href="BSplineCurve.html">BSplineCurve</a> or <a href="BSplineSurface.html">BSplineSurface</a> constructor.</li>
<li><a href="#BSplineCurve_velocity">velocity</a><br />Finds the velocity (derivative) of
this curve at the specified point.</li>
</ul>
<p><a name="BSplineCurve.DIVIDE_BIT"></a>
### BSplineCurve.DIVIDE_BIT (constant)</p>
<p>Indicates to divide each other coordinate of the returned point
by the last coordinate of the point and omit the last
coordinate. This is used to convert
homogeneous coordinates to conventional coordinates.
If this bit is set, the length of each control point must be at least 2.</p>
<p>A B-spline curve that has control points whose last coordinate is other than
1 is a <i>rational</i> B-spline curve.</p>
<p>Default Value: <code>2</code></p>
<p><a name="BSplineCurve_accel"></a>
### BSplineCurve#accel(u)</p>
<p>Finds an approximate acceleration vector at the specified u-coordinate of this curve.
The implementation in <a href="Curve.html">Curve</a> calls the evaluator’s <code>accel</code>
method if it implements it; otherwise, does a numerical differentiation using
the velocity vector.</p>
<p>The <b>acceleration</b> of a curve is a vector which is the second-order derivative of the curve’s position at the specified coordinate. The vector returned by this method <i>should not</i> be “normalized” to a unit vector.</p>
<h4 id="parameters-1">Parameters</h4>
<ul>
<li><code>u</code> (Type: number)<br />The u-coordinate of a point on the curve.</li>
</ul>
<h4 id="return-value">Return Value</h4>
<p>An array describing an acceleration vector. It should have at least as many
elements as the number of dimensions of the underlying curve. (Type: Array.<number>)</p>
<p><a name="BSplineCurve_arcLength"></a>
### BSplineCurve#arcLength(u)</p>
<p>Finds an approximate arc length (distance) between the start of this
curve and the point at the specified u-coordinate of this curve.
The implementation in <a href="Curve.html">Curve</a> calls the evaluator’s <code>arcLength</code>
method if it implements it; otherwise, calculates a numerical integral using the velocity vector.</p>
<p>The <b>arc length</b> function returns a number; if the curve is “smooth”, this is the integral, from the starting point to <code>u</code>, of the length of the velocity vector.</p>
<h4 id="parameters-2">Parameters</h4>
<ul>
<li><code>u</code> (Type: number)<br />The u-coordinate of a point on the curve.</li>
</ul>
<h4 id="return-value-1">Return Value</h4>
<p>The approximate arc length of this curve at the specified u-coordinate. (Type: number)</p>
<p><a name="BSplineCurve_changeEnds"></a>
### BSplineCurve#changeEnds(ep1, ep2)</p>
<p>Creates a curve evaluator object for a curve that is generated using
the same formula as this one (and uses the same u-coordinates),
but has a different set of end points.
For example, this method can be used to shrink the path of a curve
from [0, π] to [0, π/8].</p>
<p>Note, however, that in general, shrinking
the range of a curve will not shrink the length of a curve
in the same proportion, unless the curve’s path runs at
constant speed with respect to time. For example, shrinking the range of a curve
from [0, 1] to [0, 0.5] will not generally result in a curve that’s exactly half as
long as the original curve.</p>
<p>For some curves, this method can
also be used to grow the path of the curve.</p>
<h4 id="parameters-3">Parameters</h4>
<ul>
<li><code>ep1</code> (Type: number)<br />New start point of the curve.</li>
<li><code>ep2</code> (Type: number)<br />New end point of the curve.</li>
</ul>
<h4 id="return-value-2">Return Value</h4>
<p>Return value. (Type: <a href="Curve.html">Curve</a>)</p>
<p><a name="BSplineCurve.clamped"></a>
### (static) BSplineCurve.clamped(controlPoints, [degree], [bits])</p>
<p>Creates a B-spline curve with uniform knots, except that
the curve will start and end at the first and last control points and will
be tangent to the line between the first and second control points
and to the line between the next-to-last and last control points.</p>
<h4 id="parameters-4">Parameters</h4>
<ul>
<li><code>controlPoints</code> (Type: Array.<Array.<number»)<br />Array of control points as specified in the <a href="BSplineCurve.html">BSplineCurve</a> constructor.</li>
<li><code>degree</code> (Type: number) (optional)<br />Degree of the B-spline curve. For example, 3 means a degree-3 (cubic) curve. If null, undefined, or omitted, the default is 3.</li>
<li><code>bits</code> (Type: number) (optional)<br />Bits as specified in the <a href="BSplineCurve.html">BSplineCurve</a> constructor.</li>
</ul>
<h4 id="return-value-3">Return Value</h4>
<p>Return value. The first
knot of the curve will be 0 and the last knot will be 1. (Type: <a href="BSplineCurve.html">BSplineCurve</a>)</p>
<p><a name="BSplineCurve.clampedKnots"></a>
### (static) BSplineCurve.clampedKnots(controlPoints, [degree])</p>
<p>Generates a knot vector with uniform knots, to be
passed to the <a href="BSplineCurve.html">BSplineCurve</a> or <a href="BSplineSurface.html">BSplineSurface</a> constructor,
except that with the knot vector the curve will start and end at the first and last control points and will
be tangent to the line between the first and second control points
and to the line between the next-to-last and last control points.</p>
<h4 id="parameters-5">Parameters</h4>
<ul>
<li>
<table>
<tbody>
<tr>
<td><code>controlPoints</code> (Type: number</td>
<td>Object)<br />Number of control points the curve will have, or an array of control points.</td>
</tr>
</tbody>
</table>
</li>
<li><code>degree</code> (Type: number) (optional)<br />Degree of the B-spline curve. For example, 3 means a degree-3 (cubic) curve. If null, undefined, or omitted, the default is 3.</li>
</ul>
<h4 id="return-value-4">Return Value</h4>
<p>A clamped uniform knot vector.
The first knot will be 0 and the last knot will be 1. (Type: Array.<number>)</p>
<p><a name="BSplineCurve_endPoints"></a>
### BSplineCurve#endPoints()</p>
<p>Returns the starting and coordinates of this curve.</p>
<h4 id="return-value-5">Return Value</h4>
<p>A two-element array containing
the starting and ending u-coordinates, respectively, of the curve. (Type: Array.<number>)</p>
<p><a name="BSplineCurve_evaluate"></a>
### BSplineCurve#evaluate(u)</p>
<p>Evaluates the curve function based on a point
in a B-spline curve.</p>
<h4 id="parameters-6">Parameters</h4>
<ul>
<li><code>u</code> (Type: number)<br />Point on the curve to evaluate. This parameter is not scaled according to the curve’s knot vector. To get the curve’s extents, call this object’s <code>endPoints</code> method.</li>
</ul>
<h4 id="return-value-6">Return Value</h4>
<p>An array of the result of
the evaluation. Its length will be equal to the
length of a control point (minus 1 if DIVIDE_BIT is set), as specified in the constructor. (Type: Array.<number>)</p>
<h4 id="examples-1">Examples</h4>
<pre>// Generate 11 points forming the curve.
var points=[];
for(var i=0;i<=10;i++) {
points.push(curve.evaluate(i/10.0));
}
</pre>
<p><a name="BSplineCurve_fitRange"></a>
### BSplineCurve#fitRange(ep1, ep2)</p>
<p>Creates a curve evaluator object for a curve that follows the same
path as this one but has its u-coordinates remapped to fit the specified range.
For example, this method can be used to shrink the range of u-coordinates
from [-π, π] to [0, 1] without shortening the path of the curve.
Here, -π now maps to 0, and π now maps to 1.</p>
<h4 id="parameters-7">Parameters</h4>
<ul>
<li><code>ep1</code> (Type: number)<br />New value to use as the start point of the curve.</li>
<li><code>ep2</code> (Type: number)<br />New value to use as the end point of the curve.</li>
</ul>
<h4 id="return-value-7">Return Value</h4>
<p>Return value. (Type: <a href="Curve.html">Curve</a>)</p>
<p><a name="BSplineCurve.fromBezierCurve"></a>
### (static) BSplineCurve.fromBezierCurve(controlPoints, [bits])</p>
<p>Creates a B-spline curve from the control points of a Bézier curve.</p>
<h4 id="parameters-8">Parameters</h4>
<ul>
<li><code>controlPoints</code> (Type: Array.<Array.<number»)<br />An array of control points. Each control point is an array with the same length as the other control points. It is assumed that:<ul> <li>The length of this parameter minus 1 represents the degree of the Bézier curve. For example, a degree-3 (cubic) curve contains 4 control points. A degree of 1 (two control points) results in a straight line segment. <li>The first control point’s length represents the size of all the control points. </ul></li>
<li><code>bits</code> (Type: number) (optional)<br />Bits as specified in the <a href="BSplineCurve.html">BSplineCurve</a> constructor.</li>
</ul>
<h4 id="return-value-8">Return Value</h4>
<p>Return value. (Type: <a href="BSplineCurve.html">BSplineCurve</a>)</p>
<h4 id="examples-2">Examples</h4>
<p>The following function generates a polygon curve using linear Bézier
curves.</p>
<pre>function polygonCurve(points) {
var curves=[]
for(var i=0;i < points.length;i++) {
var cp=points[i]
var np=(i==points.length-1) ? points[0] : points[i+1]
curves.push(BSplineCurve.fromBezierCurve([cp,np]))
}
return new PiecewiseCurve(curves)
}
</pre>
<p><a name="BSplineCurve.fromConicCurve"></a>
### (static) BSplineCurve.fromConicCurve(controlPoints, lamda)</p>
<p>Creates a B-spline curve from the control points of a conic curve as described
in Apple TN1052, “QuickDraw GX ConicLibrary.c in Detail: Description and
Derivations”, 1996.</p>
<h4 id="parameters-9">Parameters</h4>
<ul>
<li><code>controlPoints</code> (Type: Array.<Array.<number»)<br />Same meaning as fromBezierCurve(), except there must be three control points.</li>
<li><code>lamda</code> (Type: number)<br />Curvature parameter, which must be 0 or greater. If 1, same as a Bézier quadratic (degree-2) curve. If 0, same as a straight line segment between the first and third control point. If less than 1 (elliptical arc), then closer to 0 means closer to that straight line. If greater than 0 (hyperbola), then the larger, the closer to the straight-line path between the first and second and then from the second to the third control point.</li>
</ul>
<h4 id="return-value-9">Return Value</h4>
<p>Return value. (Type: <a href="BSplineCurve.html">BSplineCurve</a>)</p>
<p><a name="BSplineCurve_getControlPoints"></a>
### BSplineCurve#getControlPoints()</p>
<p>Gets a reference to the array of control points used
in this curve object.</p>
<h4 id="return-value-10">Return Value</h4>
<p>An object described in the constructor to <a href="BSplineCurve.html">BSplineCurve</a>. (Type: Array.<Array.<number»)</p>
<p><a name="BSplineCurve_getKnots"></a>
### BSplineCurve#getKnots()</p>
<p>Gets a reference to the array of knots used
in this curve object.</p>
<h4 id="return-value-11">Return Value</h4>
<p>An object described in the constructor to <a href="BSplineCurve.html">BSplineCurve</a>. (Type: Array.<Array.<number»)</p>
<p><a name="BSplineCurve_getLength"></a>
### BSplineCurve#getLength()</p>
<p>Convenience method for getting the total length of this curve.</p>
<h4 id="return-value-12">Return Value</h4>
<p>The distance from the start of the curve to its end. (Type: number)</p>
<p><a name="BSplineCurve_getPoints"></a>
### BSplineCurve#getPoints(count)</p>
<p>Gets an array of positions on the curve at fixed intervals
of u-coordinates. Note that these positions will not generally be
evenly spaced along the curve unless the curve uses
an arc-length parameterization.</p>
<h4 id="parameters-10">Parameters</h4>
<ul>
<li><code>count</code> (Type: number)<br />Number of positions to generate. Throws an error if this number is 0. If this value is 1, returns an array containing the starting point of this curve.</li>
</ul>
<h4 id="return-value-13">Return Value</h4>
<p>An array of curve positions. The first
element will be the start of the curve. If “count” is 2 or greater, the last element
will be the end of the curve. (Type: Array.<Array.<number» | Array.<Object>)</p>
<p><a name="BSplineCurve_getPointsAsObjects"></a>
### BSplineCurve#getPointsAsObjects(count)</p>
<p>Gets an array of positions on the curve at fixed intervals
of u-coordinates. Note that these positions will not generally be
evenly spaced along the curve unless the curve uses
an arc-length parameterization. The positions will be in the form of objects with
up to four properties: x, y, z, and w retrieve the first, second, third,
and fourth coordinate of each position, respectively.</p>
<h4 id="parameters-11">Parameters</h4>
<ul>
<li><code>count</code> (Type: number)<br />Number of positions to generate. Throws an error if this number is 0. If this value is 1, returns an array containing the starting point of this curve.</li>
</ul>
<h4 id="return-value-14">Return Value</h4>
<p>An array of curve positions. The first
element will be the start of the curve. If “count” is 2 or greater, the last element
will be the end of the curve. (Type: Array.<Array.<number» | Array.<Object>)</p>
<h4 id="examples-3">Examples</h4>
<p>The following example initializes a three.js BufferGeometry with the points retrieved by this method. This example requires the three.js library.</p>
<pre>var points=curve.getPointsAsObjects(50)
var buffer=new THREE.BufferGeometry()
.setFromPoints(points);
</pre>
<p><a name="BSplineCurve_jerk"></a>
### BSplineCurve#jerk(u)</p>
<p>Finds an approximate jerk vector at the specified u-coordinate of this curve.
The implementation in <a href="Curve.html">Curve</a> calls the evaluator’s <code>jerk</code>
method if it implements it; otherwise, does a numerical differentiation using
the acceleration vector.</p>
<p>The <b>jerk</b> of a curve is a vector which is the third-order derivative of the curve’s position at the specified coordinate. The vector returned by this method <i>should not</i> be “normalized” to a unit vector.</p>
<h4 id="parameters-12">Parameters</h4>
<ul>
<li><code>u</code> (Type: number)<br />The u-coordinate of a point on the curve.</li>
</ul>
<h4 id="return-value-15">Return Value</h4>
<p>An array describing a jerk vector. It should have at least as many
elements as the number of dimensions of the underlying curve. (Type: Array.<number>)</p>
<p><a name="BSplineCurve_normal"></a>
### BSplineCurve#normal(u)</p>
<p>Finds an approximate principal normal vector at the specified u-coordinate of this curve.
The implementation in <a href="Curve.html">Curve</a> calls the evaluator’s <code>normal</code>
method if it implements it; otherwise, does a numerical differentiation using the velocity vector.</p>
<p>The <b>principal normal</b> of a curve is the derivative of the “normalized” velocity
vector divided by that derivative’s length. The normal returned by this method
<i>should</i> be “normalized” to a unit vector. (Compare with <a href="Surface.html#Surface_gradient">Surface#gradient</a>.)</p>
<h4 id="parameters-13">Parameters</h4>
<ul>
<li><code>u</code> (Type: number)<br />The u-coordinate of a point on the curve.</li>
</ul>
<h4 id="return-value-16">Return Value</h4>
<p>An array describing a normal vector. It should have at least as many
elements as the number of dimensions of the underlying curve. (Type: Array.<number>)</p>
<p><a name="BSplineCurve_split"></a>
### BSplineCurve#split(u)</p>
<p>Splits this B-spline curve into two at the specified point.</p>
<h4 id="parameters-14">Parameters</h4>
<ul>
<li><code>u</code> (Type: number)<br />Point on the curve where this curve will be split.</li>
</ul>
<h4 id="return-value-17">Return Value</h4>
<p>An array containing two B-spline curves: the
first is the part of the curve before the specified point, and the second
is the part of the curve after the specified point. The first element
will be null if <code>u</code> is at or before the start of the curve.
The second element
will be null if <code>u</code> is at or after the end of the curve. (Type: Array.<<a href="BSplineCurve.html">BSplineCurve</a>>)</p>
<p><a name="BSplineCurve_tangent"></a>
### BSplineCurve#tangent(u)</p>
<p>Convenience method for finding an approximate tangent vector of this curve at the specified u-coordinate.
The <b>tangent vector</b> is the same as the velocity vector, but “normalized” to a unit vector.</p>
<h4 id="parameters-15">Parameters</h4>
<ul>
<li><code>u</code> (Type: number)<br />The u-coordinate of a point on the curve.</li>
</ul>
<h4 id="return-value-18">Return Value</h4>
<p>An array describing a normal vector. It should have at least as many
elements as the number of dimensions of the underlying curve. (Type: Array.<number>)</p>
<p><a name="BSplineCurve_toArcLengthParam"></a>
### BSplineCurve#toArcLengthParam()</p>
<p>Gets a curve evaluator object for a curve that follows the same
path as this one but has its u-coordinates remapped to
an <i>arc length parameterization</i>. Arc length
parameterization allows for moving along a curve’s path at a uniform
speed and for generating points which are spaced evenly along that
path – both features are more difficult with most other kinds
of curve parameterization.</p>
<p>The <i>end points</i> of the curve (obtained by calling the <code>endPoints</code>
method) will be (0, N), where N is the distance to the end of the curve from its
start.</p>
<p>When converting to an arc length parameterization, the curve
should be continuous and have a speed greater than 0 at every
point on the curve. The arc length parameterization used in
this method is approximate.</p>
<h4 id="return-value-19">Return Value</h4>
<p>Return value. Returns this object if this curve already uses an arc length parameterization. (Type: <a href="Curve.html">Curve</a>)</p>
<h4 id="examples-4">Examples</h4>
<p>The following example uses the arc-length
parameterization to generate, uniformly at random, a point that lies anywhere
on a curve.</p>
<pre>var arclen = curve.toArcLengthParam();
var point = arclen.evaluate(Math.random()*arclen.getLength())
</pre>
<p><a name="BSplineCurve.uniform"></a>
### (static) BSplineCurve.uniform(controlPoints, [degree], [bits])</p>
<p>Creates a B-spline curve with uniform knots.</p>
<h4 id="parameters-16">Parameters</h4>
<ul>
<li><code>controlPoints</code> (Type: Array.<Array.<number»)<br />Array of control points as specified in the <a href="BSplineCurve.html">BSplineCurve</a> constructor.</li>
<li><code>degree</code> (Type: number) (optional)<br />Degree of the B-spline curve. For example, 3 means a degree-3 (cubic) curve. If null, undefined, or omitted, the default is 3.</li>
<li><code>bits</code> (Type: number) (optional)<br />Bits as specified in the <a href="BSplineCurve.html">BSplineCurve</a> constructor.</li>
</ul>
<h4 id="return-value-20">Return Value</h4>
<p>Return value. The first
knot of the curve will be 0 and the last knot will be 1. (This is a change from previous
versions.) (Type: <a href="BSplineCurve.html">BSplineCurve</a>)</p>
<p><a name="BSplineCurve.uniformKnots"></a>
### (static) BSplineCurve.uniformKnots(controlPoints, [degree])</p>
<p>Generates a knot vector with uniform knots, to be
passed to the <a href="BSplineCurve.html">BSplineCurve</a> or <a href="BSplineSurface.html">BSplineSurface</a> constructor.</p>
<h4 id="parameters-17">Parameters</h4>
<ul>
<li>
<table>
<tbody>
<tr>
<td><code>controlPoints</code> (Type: number</td>
<td>Object)<br />Number of control points the curve will have, or an array of control points.</td>
</tr>
</tbody>
</table>
</li>
<li><code>degree</code> (Type: number) (optional)<br />Degree of the B-spline curve. For example, 3 means a degree-3 (cubic) curve. If null, undefined, or omitted, the default is 3.</li>
</ul>
<h4 id="return-value-21">Return Value</h4>
<p>A uniform knot vector. The first
knot will be 0 and the last knot will be 1. (This is a change from previous
versions.) (Type: Array.<number>)</p>
<p><a name="BSplineCurve_velocity"></a>
### BSplineCurve#velocity(u)</p>
<p>Finds the velocity (derivative) of
this curve at the specified point.</p>
<h4 id="parameters-18">Parameters</h4>
<ul>
<li><code>u</code> (Type: number)<br />Point on the curve to evaluate.</li>
</ul>
<h4 id="return-value-22">Return Value</h4>
<p>An array giving the velocity vector.
It will have as many elements as a control point (or one fewer
if DIVIDE_BIT is set), as specified in the constructor. (Type: Array.<number>)</p>
<p><a href="index.html">Back to documentation index.</a></p>
</div><nav id="navigation"><ul>
<li><a href="/">Back to start site.</a>
<li><a href="https://github.com/peteroupc/peteroupc.github.io">This site's repository (source code)</a>
<li><a href="https://github.com/peteroupc/peteroupc.github.io/issues">Post an issue or comment</a></ul>
<div class="noprint">
<p>
<a href="//twitter.com/intent/tweet">Share via Twitter</a>, <a href="//www.facebook.com/sharer/sharer.php" id="sharer">Share via Facebook</a>
</p>
</div>
<h3 id="navigation">Navigation</h3>
<ul>
<li><a href="BSplineCurve.html">BSplineCurve</a></li>
<li><a href="BSplineSurface.html">BSplineSurface</a></li>
<li><a href="Curve.html">Curve</a></li>
<li><a href="CurveBuilder.html">CurveBuilder</a></li>
<li><a href="GraphicsPath.html">GraphicsPath</a></li>
<li><a href="H3DU.html">H3DU</a></li>
<li><a href="MathUtil.html">MathUtil</a></li>
<li><a href="MeshBuffer.html">MeshBuffer</a></li>
<li><a href="Meshes.html">Meshes</a></li>
<li><a href="PiecewiseCurve.html">PiecewiseCurve</a></li>
<li><a href="Surface.html">Surface</a></li>
<li><a href="SurfaceBuilder.html">SurfaceBuilder</a></li>
<li><a href="Transform.html">Transform</a></li>
<li><a href="extras_camera.html">module:extras/camera</a></li>
<li><a href="extras_camera.Camera.html">module:extras/camera.Camera</a></li>
<li><a href="extras_camera.InputTracker.html">module:extras/camera.InputTracker</a></li>
<li><a href="extras_createwasher.html">module:extras/createwasher</a></li>
<li><a href="extras_curvetube.html">module:extras/curvetube</a></li>
<li><a href="extras_curvetube.CurveTube.html">module:extras/curvetube.CurveTube</a></li>
<li><a href="extras_derivedcurves.html">module:extras/derivedcurves</a></li>
<li><a href="extras_evaluators.html">module:extras/evaluators</a></li>
<li><a href="extras_evaluators.Roulette.html">module:extras/evaluators.Roulette</a></li>
<li><a href="extras_evaluators.SurfaceOfRevolution.html">module:extras/evaluators.SurfaceOfRevolution</a></li>
<li><a href="extras_fourierknot.html">module:extras/fourierknot</a></li>
<li><a href="extras_gradients.html">module:extras/gradients</a></li>
<li><a href="extras_matrixstack.html">module:extras/matrixstack</a></li>
<li><a href="extras_matrixstack.MatrixStack.html">module:extras/matrixstack.MatrixStack</a></li>
<li><a href="extras_meshes_arrow.html">module:extras/meshes/arrow</a></li>
<li><a href="extras_meshes_contourlines.html">module:extras/meshes/contourlines</a></li>
<li><a href="extras_meshes_convex.html">module:extras/meshes/convex</a></li>
<li><a href="extras_meshes_createfloor.html">module:extras/meshes/createfloor</a></li>
<li><a href="extras_meshes_drawingtoy.html">module:extras/meshes/drawingtoy</a></li>
<li><a href="extras_meshes_drawingtoy.DrawingToy.html">module:extras/meshes/drawingtoy.DrawingToy</a></li>
<li><a href="extras_meshes_gearmesh.html">module:extras/meshes/gearmesh</a></li>
<li><a href="extras_meshes_pathtomesh.html">module:extras/meshes/pathtomesh</a></li>
<li><a href="extras_meshes_polyhedra.html">module:extras/meshes/polyhedra</a></li>
<li><a href="extras_meshes_polyhedra.Polyhedra.html">module:extras/meshes/polyhedra.Polyhedra</a></li>
<li><a href="extras_meshes_raypick.html">module:extras/meshes/raypick</a></li>
<li><a href="extras_meshes_starfield.html">module:extras/meshes/starfield</a></li>
<li><a href="extras_meshes_starfield.StarField.html">module:extras/meshes/starfield.StarField</a></li>
<li><a href="extras_meshes_stl.html">module:extras/meshes/stl</a></li>
<li><a href="extras_meshes_text.html">module:extras/meshes/text</a></li>
<li><a href="extras_meshes_text.TextFont.html">module:extras/meshes/text.TextFont</a></li>
<li><a href="extras_moresurfaces.html">module:extras/moresurfaces</a></li>
<li><a href="extras_moresurfaces.KleinBottle.html">module:extras/moresurfaces.KleinBottle</a></li>
<li><a href="extras_moresurfaces.MoebiusStrip.html">module:extras/moresurfaces.MoebiusStrip</a></li>
<li><a href="extras_pathutil.html">module:extras/pathutil</a></li>
<li><a href="extras_randompolygon.html">module:extras/randompolygon</a></li>
<li><a href="extras_shaders_checkerboardshader.html">module:extras/shaders/checkerboardshader</a></li>
<li><a href="extras_shaders_colormatrixshader.html">module:extras/shaders/colormatrixshader</a></li>
<li><a href="extras_shaders_fragmentshaderlib.html">module:extras/shaders/fragmentshaderlib</a></li>
<li><a href="extras_shaders_horgradshader.html">module:extras/shaders/horgradshader</a></li>
<li><a href="extras_shaders_kernelmatrixshader.html">module:extras/shaders/kernelmatrixshader</a></li>
<li><a href="extras_shaders_marbleshader.html">module:extras/shaders/marbleshader</a></li>
<li><a href="extras_shaders_marbleshader2.html">module:extras/shaders/marbleshader2</a></li>
<li><a href="extras_shaders_mirrorshader.html">module:extras/shaders/mirrorshader</a></li>
<li><a href="extras_shaders_pixelateshader.html">module:extras/shaders/pixelateshader</a></li>
<li><a href="extras_shaders_radgradshader.html">module:extras/shaders/radgradshader</a></li>
<li><a href="extras_shaders_skysphereshader.html">module:extras/shaders/skysphereshader</a></li>
<li><a href="extras_shaders_stripesbackshader.html">module:extras/shaders/stripesbackshader</a></li>
<li><a href="extras_shaders_sunburstbackshader.html">module:extras/shaders/sunburstbackshader</a></li>
<li><a href="extras_shaders_vignetteshader.html">module:extras/shaders/vignetteshader</a></li>
<li><a href="extras_shaders_warpshader.html">module:extras/shaders/warpshader</a></li>
<li><a href="extras_shaders_waterpaintshader.html">module:extras/shaders/waterpaintshader</a></li>
<li><a href="extras_shaders_waveshader.html">module:extras/shaders/waveshader</a></li>
<li><a href="extras_shaders_woodshader.html">module:extras/shaders/woodshader</a></li>
<li><a href="extras_starpolygon.html">module:extras/starpolygon</a></li>
<li><a href="extras_superellipsoid.html">module:extras/superellipsoid</a></li>
<li><a href="extras_superellipsoid.Supershape.html">module:extras/superellipsoid.Supershape</a></li>
<li><a href="extras_superellipsoid.Supertoroid.html">module:extras/superellipsoid.Supertoroid</a></li>
<li><a href="extras_torusknot.html">module:extras/torusknot</a></li>
<li><a href="extras_torusknot.TorusKnot.html">module:extras/torusknot.TorusKnot</a></li>
</ul>
</nav></body></html>