Curve.js 15.1 KB
Newer Older
Z
curves  
zz85 已提交
1 2
/**
 * @author zz85 / http://www.lab4games.net/zz85/blog
3
 * Extensible curve object
Z
zz85 已提交
4 5 6 7 8 9
 * 
 * Some common of Curve methods
 * .getPoint(t), getTangent(t)
 * .getPointAt(u), getTagentAt(u)
 * .getPoints(), .getSpacedPoints()
 * .getLength()
10 11 12
 *
 * This file contains following classes:
 *
Z
zz85 已提交
13
 * -- 2d classes --
14 15 16 17 18 19
 * THREE.Curve
 * THREE.LineCurve
 * THREE.QuadraticBezierCurve
 * THREE.CubicBezierCurve
 * THREE.SplineCurve
 * THREE.ArcCurve
20
 *
Z
zz85 已提交
21 22 23 24 25
 * -- 3d classes --
 * THREE.LineCurve3
 * THREE.QuadraticBezierCurve3
 * THREE.CubicBezierCurve3
 * THREE.SplineCurve3
Z
curves  
zz85 已提交
26 27 28
 *
 **/

29 30 31 32
/**************************************************************
 *	Abstract Curve base class
 **************************************************************/

33
THREE.Curve = function () {
34

Z
curves  
zz85 已提交
35 36
};

37 38 39 40 41 42
// Virtual base class method to overwrite and implement in subclasses
//	- t [0 .. 1]

THREE.Curve.prototype.getPoint = function ( t ) {

	console.log( "Warning, getPoint() not implemented!" );
Z
curves  
zz85 已提交
43
	return null;
44

Z
curves  
zz85 已提交
45 46
};

47 48 49 50 51 52 53 54
// Get point at relative position in curve according to arc length
// - u [0 .. 1]

THREE.Curve.prototype.getPointAt = function ( u ) {

	var t = this.getUtoTmapping( u );
	return this.getPoint( t );

Z
curves  
zz85 已提交
55 56
};

57 58 59 60 61 62
// Get sequence of points using getPoint( t )

THREE.Curve.prototype.getPoints = function ( divisions ) {

	if ( !divisions ) divisions = 5;

Z
curves  
zz85 已提交
63
	var d, pts = [];
64 65 66 67 68

	for ( d = 0; d <= divisions; d ++ ) {

		pts.push( this.getPoint( d / divisions ) );

Z
curves  
zz85 已提交
69
	};
70

Z
curves  
zz85 已提交
71
	return pts;
72

Z
curves  
zz85 已提交
73 74
};

75 76 77 78 79 80
// Get sequence of points using getPointAt( u )

THREE.Curve.prototype.getSpacedPoints = function ( divisions ) {

	if ( !divisions ) divisions = 5;

Z
curves  
zz85 已提交
81
	var d, pts = [];
82 83 84 85 86

	for ( d = 0; d <= divisions; d ++ ) {

		pts.push( this.getPointAt( d / divisions ) );

Z
curves  
zz85 已提交
87
	};
88

Z
curves  
zz85 已提交
89
	return pts;
90

Z
curves  
zz85 已提交
91 92
};

93 94
// Get total curve length

Z
curves  
zz85 已提交
95
THREE.Curve.prototype.getLength = function () {
96

Z
curves  
zz85 已提交
97
	var lengths = this.getLengths();
98 99
	return lengths[ lengths.length - 1 ];

Z
curves  
zz85 已提交
100 101
};

102 103
// Get list of cumulative segment lengths

104
THREE.Curve.prototype.getLengths = function ( divisions ) {
105 106 107

	if ( !divisions ) divisions = 200;

108
	if ( this.cacheArcLengths && ( this.cacheArcLengths.length == divisions + 1 ) ) {
109

110 111
		//console.log( "cached", this.cacheArcLengths );
		return this.cacheArcLengths;
112

Z
curves  
zz85 已提交
113
	}
114

Z
curves  
zz85 已提交
115
	var cache = [];
116 117 118
	var current, last = this.getPoint( 0 );
	var p, sum = 0;

119 120 121
	cache.push( 0 );

	for ( p = 1; p <= divisions; p ++ ) {
122 123 124 125

		current = this.getPoint ( p / divisions );
		sum += current.distanceTo( last );
		cache.push( sum );
Z
curves  
zz85 已提交
126
		last = current;
127

Z
curves  
zz85 已提交
128
	}
129

130
	this.cacheArcLengths = cache;
131

132 133
	return cache; // { sums: cache, sum:sum }; Sum is in the last element.

Z
curves  
zz85 已提交
134 135
};

136 137
// Given u ( 0 .. 1 ), get a t to find p. This gives you points which are equi distance

138
THREE.Curve.prototype.getUtoTmapping = function ( u, distance ) {
139

Z
zz85 已提交
140
	var arcLengths = this.getLengths();
Z
curves  
zz85 已提交
141

Z
zz85 已提交
142
	var i = 0, il = arcLengths.length;
Z
curves  
zz85 已提交
143

144
	var targetArcLength; // The targeted u distance value to get
145 146 147

	if ( distance ) {

Z
zz85 已提交
148
		targetArcLength = distance;
149

Z
curves  
zz85 已提交
150
	} else {
151

Z
zz85 已提交
152
		targetArcLength = u * arcLengths[ il - 1 ];
153

Z
curves  
zz85 已提交
154
	}
155

Z
zz85 已提交
156
	//var time = Date.now();
157

Z
zz85 已提交
158 159
	// binary search for the index with largest value smaller than target u distance

160 161 162 163 164
	var low = 0, high = il - 1, comparison;

	while ( low <= high ) {

		i = Math.floor( low + ( high - low ) / 2 ); // less likely to overflow, though probably not issue here, JS doesn't really have integers, all numbers are floats
Z
zz85 已提交
165 166

	  	comparison = arcLengths[ i ] - targetArcLength;
167 168 169 170 171

	  	if ( comparison < 0 ) {

			low = i + 1;
			continue;
172

173
		} else if ( comparison > 0 ) {
174

175 176
			high = i - 1;
			continue;
177

Z
zz85 已提交
178
		} else {
179

Z
zz85 已提交
180 181
			high = i;
			break;
182

Z
zz85 已提交
183
			// DONE
184

Z
zz85 已提交
185
		}
186

Z
curves  
zz85 已提交
187
	}
188

Z
zz85 已提交
189
	i = high;
190

Z
zz85 已提交
191 192
	//console.log('b' , i, low, high, Date.now()- time);

193 194 195
	if ( arcLengths[ i ] == targetArcLength ) {

		var t = i / ( il - 1 );
Z
zz85 已提交
196
		return t;
197

Z
zz85 已提交
198
	}
199 200 201 202 203 204

	// we could get finer grain at lengths, or use simple interpolatation between two points

	var lengthBefore = arcLengths[ i ];
    var lengthAfter = arcLengths[ i + 1 ];

Z
zz85 已提交
205
    var segmentLength = lengthAfter - lengthBefore;
206

207 208 209 210 211
    // determine where we are between the 'before' and 'after' points

    var segmentFraction = ( targetArcLength - lengthBefore ) / segmentLength;

    // add that fractional amount to t
212

213
    t = ( i + segmentFraction ) / ( il -1 );
214

Z
curves  
zz85 已提交
215
	return t;
216

Z
curves  
zz85 已提交
217 218
};

219 220
// In case any sub curve does not implement its tangent / normal finding,
// we get 2 points with a small delta and find a gradient of the 2 points
221
// which seems to make a reasonable approximation
Z
zz85 已提交
222 223 224

THREE.Curve.prototype.getNormalVector = function( t ) {

225 226
	var vec = this.getTangent( t );

227
	return new THREE.Vector2( -vec.y , vec.x );
Z
zz85 已提交
228 229 230

};

231
// Returns a unit vector tangent at t
232

233
THREE.Curve.prototype.getTangent = function( t ) {
Z
zz85 已提交
234

235
	var delta = 0.0001;
236 237
	var t1 = t - delta;
	var t2 = t + delta;
Z
zz85 已提交
238

239
	// Capping in case of danger
Z
zz85 已提交
240

241 242
	if ( t1 < 0 ) t1 = 0;
	if ( t2 > 1 ) t2 = 1;
Z
zz85 已提交
243

244 245
	var pt1 = this.getPoint( t1 );
	var pt2 = this.getPoint( t2 );
Z
zz85 已提交
246 247 248
	
	var vec = pt1.clone().subSelf(pt2);
	return vec.normalize();
249

250
};
251

Z
curves  
zz85 已提交
252

Z
zz85 已提交
253 254 255 256 257 258 259
THREE.Curve.prototype.getTangentAt = function ( u ) {

	var t = this.getUtoTmapping( u );
	return this.getTangent( t );

};

260 261 262 263
/**************************************************************
 *	Line
 **************************************************************/

Z
zz85 已提交
264
THREE.LineCurve = function ( v1, v2 ) {
265 266 267

	if ( ! ( v1 instanceof THREE.Vector2 ) ) {

268
		// Fall back for old constuctor signature - should be removed over time
Z
curves  
zz85 已提交
269

270
		THREE.LineCurve.oldConstructor.apply( this, arguments );
271
		return;
272

273
	}
Z
zz85 已提交
274 275 276

	this.v1 = v1;
	this.v2 = v2;
277

278
};
279

280
THREE.LineCurve.oldConstructor = function ( x1, y1, x2, y2 ) {
281 282

	this.constructor( new THREE.Vector2( x1, y1 ), new THREE.Vector2( x2, y2 ) );
283

Z
curves  
zz85 已提交
284 285
};

286 287 288 289
THREE.LineCurve.prototype = new THREE.Curve();
THREE.LineCurve.prototype.constructor = THREE.LineCurve;

THREE.LineCurve.prototype.getPoint = function ( t ) {
Z
curves  
zz85 已提交
290

291
	var point = new THREE.Vector2();
292

293 294
	point.sub( this.v2, this.v1 );
	point.multiplyScalar( t ).addSelf( this.v1 );
Z
curves  
zz85 已提交
295

296 297
	return point;

Z
curves  
zz85 已提交
298 299
};

300
// Line curve is linear, so we can overwrite default getPointAt
301

302
THREE.LineCurve.prototype.getPointAt = function ( u ) {
303

304
	return this.getPoint( u );
305

306 307
};

308
THREE.LineCurve.prototype.getTangent = function( t ) {
309 310 311 312 313 314 315

	var tangent = new THREE.Vector2();

	tangent.sub( this.v2, this.v1 );
	tangent.normalize();

	return tangent;
316

Z
curves  
zz85 已提交
317 318
};

319 320 321 322 323
/**************************************************************
 *	Quadratic Bezier curve
 **************************************************************/


Z
zz85 已提交
324
THREE.QuadraticBezierCurve = function ( v0, v1, v2 ) {
325 326 327 328

	if ( !( v1 instanceof THREE.Vector2 ) ) {

		var args = Array.prototype.slice.call( arguments );
329

330 331 332 333
		v0 = new THREE.Vector2( args[ 0 ], args[ 1 ] );
		v1 = new THREE.Vector2( args[ 2 ], args[ 3 ] );
		v2 = new THREE.Vector2( args[ 4 ], args[ 5 ] );

334
	}
335

Z
zz85 已提交
336 337 338
	this.v0 = v0;
	this.v1 = v1;
	this.v2 = v2;
339

Z
curves  
zz85 已提交
340 341 342 343 344
};

THREE.QuadraticBezierCurve.prototype = new THREE.Curve();
THREE.QuadraticBezierCurve.prototype.constructor = THREE.QuadraticBezierCurve;

345 346 347

THREE.QuadraticBezierCurve.prototype.getPoint = function ( t ) {

Z
curves  
zz85 已提交
348 349
	var tx, ty;

Z
zz85 已提交
350 351
	tx = THREE.Shape.Utils.b2( t, this.v0.x, this.v1.x, this.v2.x );
	ty = THREE.Shape.Utils.b2( t, this.v0.y, this.v1.y, this.v2.y );
Z
curves  
zz85 已提交
352 353

	return new THREE.Vector2( tx, ty );
354

Z
curves  
zz85 已提交
355 356
};

Z
zz85 已提交
357

358
THREE.QuadraticBezierCurve.prototype.getTangent = function( t ) {
359

Z
zz85 已提交
360 361 362
	// iterate sub segments
	// 	get lengths for sub segments
	// 	if segment is bezier
363
	//		perform subdivisions
364

Z
zz85 已提交
365
	var tx, ty;
366

Z
zz85 已提交
367 368
	tx = THREE.Curve.Utils.tangentQuadraticBezier( t, this.v0.x, this.v1.x, this.v2.x );
	ty = THREE.Curve.Utils.tangentQuadraticBezier( t, this.v0.y, this.v1.y, this.v2.y );
369

370
	// returns unit vector
371

372 373
	var tangent = new THREE.Vector2( tx, ty );
	tangent.normalize();
374

375
	return tangent;
376

Z
zz85 已提交
377 378 379
};


380 381 382 383
/**************************************************************
 *	Cubic Bezier curve
 **************************************************************/

Z
zz85 已提交
384
THREE.CubicBezierCurve = function ( v0, v1, v2, v3 ) {
385

386
	if ( ! ( v1 instanceof THREE.Vector2 ) ) {
387

388
		var args = Array.prototype.slice.call( arguments );
389

390 391 392 393
		v0 = new THREE.Vector2( args[ 0 ], args[ 1 ] );
		v1 = new THREE.Vector2( args[ 2 ], args[ 3 ] );
		v2 = new THREE.Vector2( args[ 4 ], args[ 5 ] );
		v3 = new THREE.Vector2( args[ 6 ], args[ 7 ] );
394

395 396
	}

Z
zz85 已提交
397 398 399 400
	this.v0 = v0;
	this.v1 = v1;
	this.v2 = v2;
	this.v3 = v3;
401

Z
curves  
zz85 已提交
402
};
403

Z
curves  
zz85 已提交
404 405 406
THREE.CubicBezierCurve.prototype = new THREE.Curve();
THREE.CubicBezierCurve.prototype.constructor = THREE.CubicBezierCurve;

407 408
THREE.CubicBezierCurve.prototype.getPoint = function ( t ) {

Z
curves  
zz85 已提交
409 410
	var tx, ty;

Z
zz85 已提交
411 412
	tx = THREE.Shape.Utils.b3( t, this.v0.x, this.v1.x, this.v2.x, this.v3.x );
	ty = THREE.Shape.Utils.b3( t, this.v0.y, this.v1.y, this.v2.y, this.v3.y );
Z
curves  
zz85 已提交
413 414

	return new THREE.Vector2( tx, ty );
415

Z
curves  
zz85 已提交
416 417
};

418
THREE.CubicBezierCurve.prototype.getTangent = function( t ) {
Z
zz85 已提交
419 420 421 422 423 424 425

	var tx, ty;

	tx = THREE.Curve.Utils.tangentCubicBezier( t, this.v0.x, this.v1.x, this.v2.x, this.v3.x );
	ty = THREE.Curve.Utils.tangentCubicBezier( t, this.v0.y, this.v1.y, this.v2.y, this.v3.y );

	// return normal unit vector
426 427 428 429 430

	var tangent = new THREE.Vector2( tx, ty );
	tangent.normalize();

	return tangent;
Z
zz85 已提交
431 432 433 434

};


435 436 437 438
/**************************************************************
 *	Spline curve
 **************************************************************/

439
THREE.SplineCurve = function ( points /* array of Vector2 */ ) {
440

Z
zz85 已提交
441
	this.points = (points == undefined) ? [] : points;
442

Z
curves  
zz85 已提交
443 444 445
};

THREE.SplineCurve.prototype = new THREE.Curve();
Z
zz85 已提交
446
THREE.SplineCurve.prototype.constructor = THREE.SplineCurve;
Z
curves  
zz85 已提交
447

448
THREE.SplineCurve.prototype.getPoint = function ( t ) {
Z
curves  
zz85 已提交
449 450 451

	var v = new THREE.Vector2();
	var c = [];
452
	var points = this.points, point, intPoint, weight;
Z
curves  
zz85 已提交
453 454 455 456 457 458 459 460 461 462 463 464 465 466 467
	point = ( points.length - 1 ) * t;

	intPoint = Math.floor( point );
	weight = point - intPoint;

	c[ 0 ] = intPoint == 0 ? intPoint : intPoint - 1;
	c[ 1 ] = intPoint;
	c[ 2 ] = intPoint > points.length - 2 ? intPoint : intPoint + 1;
	c[ 3 ] = intPoint > points.length - 3 ? intPoint : intPoint + 2;

	v.x = THREE.Curve.Utils.interpolate( points[ c[ 0 ] ].x, points[ c[ 1 ] ].x, points[ c[ 2 ] ].x, points[ c[ 3 ] ].x, weight );
	v.y = THREE.Curve.Utils.interpolate( points[ c[ 0 ] ].y, points[ c[ 1 ] ].y, points[ c[ 2 ] ].y, points[ c[ 3 ] ].y, weight );

	return v;

468
};
Z
zz85 已提交
469

470 471 472
/**************************************************************
 *	Arc curve
 **************************************************************/
Z
zz85 已提交
473 474

THREE.ArcCurve = function ( aX, aY, aRadius,
A
alteredq 已提交
475 476 477
							aStartAngle, aEndAngle,
							aClockwise ) {

Z
zz85 已提交
478 479
	this.aX = aX;
	this.aY = aY;
480

Z
zz85 已提交
481
	this.aRadius = aRadius;
482

Z
zz85 已提交
483 484
	this.aStartAngle = aStartAngle;
	this.aEndAngle = aEndAngle;
485

Z
zz85 已提交
486
	this.aClockwise = aClockwise;
487

Z
zz85 已提交
488 489 490 491 492
};

THREE.ArcCurve.prototype = new THREE.Curve();
THREE.ArcCurve.prototype.constructor = THREE.ArcCurve;

493
THREE.ArcCurve.prototype.getPoint = function ( t ) {
Z
zz85 已提交
494 495

	var deltaAngle = this.aEndAngle - this.aStartAngle;
496 497 498

	if ( !this.aClockwise ) {

Z
zz85 已提交
499
		t = 1 - t;
500

Z
zz85 已提交
501
	}
502

Z
zz85 已提交
503 504
	var angle = this.aStartAngle + t * deltaAngle;

505 506
	var tx = this.aX + this.aRadius * Math.cos( angle );
	var ty = this.aY + this.aRadius * Math.sin( angle );
Z
zz85 已提交
507 508 509

	return new THREE.Vector2( tx, ty );

510 511 512 513 514
};

/**************************************************************
 *	Utils
 **************************************************************/
Z
zz85 已提交
515

Z
curves  
zz85 已提交
516
THREE.Curve.Utils = {
517 518 519 520 521

	tangentQuadraticBezier: function ( t, p0, p1, p2 ) {

		return 2 * ( 1 - t ) * ( p1 - p0 ) + 2 * t * ( p2 - p1 );

Z
zz85 已提交
522
	},
523

524
	// Puay Bing, thanks for helping with this derivative!
525

Z
zz85 已提交
526
	tangentCubicBezier: function (t, p0, p1, p2, p3 ) {
527

Z
zz85 已提交
528 529
		return -3 * p0 * (1 - t) * (1 - t)  +
			3 * p1 * (1 - t) * (1-t) - 6 *t *p1 * (1-t) +
530
			6 * t *  p2 * (1-t) - 3 * t * t * p2 +
Z
zz85 已提交
531 532
			3 * t * t * p3;
	},
533

534 535 536

	tangentSpline: function ( t, p0, p1, p2, p3 ) {

Z
zz85 已提交
537
		// To check if my formulas are correct
538 539

		var h00 = 6 * t * t - 6 * t; 	// derived from 2t^3 − 3t^2 + 1
Z
zz85 已提交
540
		var h10 = 3 * t * t - 4 * t + 1; // t^3 − 2t^2 + t
541 542 543
		var h01 = -6 * t * t + 6 * t; 	// − 2t3 + 3t2
		var h11 = 3 * t * t - 2 * t;	// t3 − t2

544
		return h00 + h10 + h01 + h11;
545

Z
zz85 已提交
546
	},
547

Z
curves  
zz85 已提交
548
	// Catmull-Rom
549

Z
curves  
zz85 已提交
550 551 552 553 554 555 556 557 558
	interpolate: function( p0, p1, p2, p3, t ) {

		var v0 = ( p2 - p0 ) * 0.5;
		var v1 = ( p3 - p1 ) * 0.5;
		var t2 = t * t;
		var t3 = t * t2;
		return ( 2 * p1 - 2 * p2 + v0 + v1 ) * t3 + ( - 3 * p1 + 3 * p2 - 2 * v0 - v1 ) * t2 + v0 * t + p1;

	}
559

Z
curves  
zz85 已提交
560 561 562 563 564 565 566 567 568 569 570
};


/*
getPoint DONE
getLength DONE
getLengths DONE

curve.getPoints(); DONE
curve.getPointAtArcLength(t); DONE
curve.transform(params);
571
curve.getTangentAt(t); DONE
572 573 574 575 576 577
*/

/**************************************************************
 *	3D Curves
 **************************************************************/

578 579 580
// A Factory method for creating new curve subclasses

THREE.Curve.create = function( constructor, getPointFunc ) {
581 582 583

    var subClass = constructor;

584 585 586 587 588 589 590 591
	subClass.prototype = new THREE.Curve();

	subClass.prototype.constructor = constructor;
    subClass.prototype.getPoint = getPointFunc;

	return subClass;

};
592 593 594 595 596 597 598 599


/**************************************************************
 *	Line3D
 **************************************************************/

THREE.LineCurve3 = THREE.Curve.create(

600
	function ( v1, v2 ) {
601

602 603
		this.v1 = v1;
		this.v2 = v2;
604 605

	},
606

607 608
	function ( t ) {

609
		var r = new THREE.Vector3();
610

611

612
		r.sub( this.v2, this.v1 ); // diff
613 614
		r.multiplyScalar( t );
		r.addSelf( this.v1 );
615

616
		return r;
617 618

	}
619

620 621 622 623 624 625 626 627 628
);


/**************************************************************
 *	Quadratic Bezier 3D curve
 **************************************************************/

THREE.QuadraticBezierCurve3 = THREE.Curve.create(

Z
zz85 已提交
629
	function ( v0, v1, v2 ) {
630

631 632 633
		this.v0 = v0;
		this.v1 = v1;
		this.v2 = v2;
634 635

	},
636

637 638 639 640
	function ( t ) {

		var tx, ty, tz;

641 642 643
		tx = THREE.Shape.Utils.b2( t, this.v0.x, this.v1.x, this.v2.x );
		ty = THREE.Shape.Utils.b2( t, this.v0.y, this.v1.y, this.v2.y );
		tz = THREE.Shape.Utils.b2( t, this.v0.z, this.v1.z, this.v2.z );
644

645
		return new THREE.Vector3( tx, ty, tz );
646 647

	}
648

Z
zz85 已提交
649
);
Z
zz85 已提交
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



/**************************************************************
 *	Cubic Bezier 3D curve
 **************************************************************/

THREE.CubicBezierCurve3 = THREE.Curve.create(

	function ( v0, v1, v2, v3 ) {

		this.v0 = v0;
		this.v1 = v1;
		this.v2 = v2;
		this.v3 = v3;

	},

	function ( t ) {

		var tx, ty, tz;

		tx = THREE.Shape.Utils.b3( t, this.v0.x, this.v1.x, this.v2.x, this.v3.x );
		ty = THREE.Shape.Utils.b3( t, this.v0.y, this.v1.y, this.v2.y, this.v3.y );
		tz = THREE.Shape.Utils.b3( t, this.v0.z, this.v1.z, this.v2.z, this.v3.z );

		return new THREE.Vector3( tx, ty, tz );

	}

);



/**************************************************************
 *	Spline 3D curve
 **************************************************************/


THREE.SplineCurve3 = THREE.Curve.create(

	function ( points /* array of Vector3 */) {

Z
zz85 已提交
693
		this.points = (points == undefined) ? [] : points;
694

Z
zz85 已提交
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
	},

	function ( t ) {

		var v = new THREE.Vector3();
		var c = [];
		var points = this.points, point, intPoint, weight;
		point = ( points.length - 1 ) * t;

		intPoint = Math.floor( point );
		weight = point - intPoint;

		c[ 0 ] = intPoint == 0 ? intPoint : intPoint - 1;
		c[ 1 ] = intPoint;
		c[ 2 ] = intPoint > points.length - 2 ? intPoint : intPoint + 1;
		c[ 3 ] = intPoint > points.length - 3 ? intPoint : intPoint + 2;

		v.x = THREE.Curve.Utils.interpolate( points[ c[ 0 ] ].x, points[ c[ 1 ] ].x, points[ c[ 2 ] ].x, points[ c[ 3 ] ].x, weight );
		v.y = THREE.Curve.Utils.interpolate( points[ c[ 0 ] ].y, points[ c[ 1 ] ].y, points[ c[ 2 ] ].y, points[ c[ 3 ] ].y, weight );
		v.z = THREE.Curve.Utils.interpolate( points[ c[ 0 ] ].z, points[ c[ 1 ] ].z, points[ c[ 2 ] ].z, points[ c[ 3 ] ].z, weight );

		return v;

	}

);