Vector3.js 12.5 KB
Newer Older
M
Mr.doob 已提交
1
/**
M
Mr.doob 已提交
2
 * @author mrdoob / http://mrdoob.com/
3
 * @author *kile / http://kile.stravaganza.org/
M
Mr.doob 已提交
4
 * @author philogb / http://blog.thejit.org/
5
 * @author mikael emtinger / http://gomo.se/
M
Mr.doob 已提交
6
 * @author egraether / http://egraether.com/
W
WestLangley 已提交
7
 * @author WestLangley / http://github.com/WestLangley
M
Mr.doob 已提交
8 9
 */

A
alteredq 已提交
10
THREE.Vector3 = function ( x, y, z ) {
11

12 13 14
	this.x = x || 0;
	this.y = y || 0;
	this.z = z || 0;
M
Mr.doob 已提交
15

16
};
17

18
THREE.extend( THREE.Vector3.prototype, {
19

20
	set: function ( x, y, z ) {
M
Mr.doob 已提交
21

A
alteredq 已提交
22 23 24
		this.x = x;
		this.y = y;
		this.z = z;
M
Mr.doob 已提交
25

26
		return this;
27

28
	},
29

M
Mr.doob 已提交
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
	setX: function ( x ) {

		this.x = x;

		return this;

	},

	setY: function ( y ) {

		this.y = y;

		return this;

	},

	setZ: function ( z ) {

		this.z = z;

		return this;

	},

M
Mr.doob 已提交
54
	setComponent: function ( index, value ) {
B
Ben Houston 已提交
55

M
Mr.doob 已提交
56
		switch ( index ) {
57

M
Mr.doob 已提交
58 59 60 61
			case 0: this.x = value; break;
			case 1: this.y = value; break;
			case 2: this.z = value; break;
			default: throw new Error( "index is out of range: " + index );
B
Ben Houston 已提交
62

M
Mr.doob 已提交
63
		}
B
Ben Houston 已提交
64

M
Mr.doob 已提交
65
	},
66

M
Mr.doob 已提交
67
	getComponent: function ( index ) {
68

M
Mr.doob 已提交
69
		switch ( index ) {
70

M
Mr.doob 已提交
71 72 73 74
			case 0: return this.x;
			case 1: return this.y;
			case 2: return this.z;
			default: throw new Error( "index is out of range: " + index );
75

M
Mr.doob 已提交
76
		}
77

M
Mr.doob 已提交
78
	},
79

80
	copy: function ( v ) {
M
Mr.doob 已提交
81

M
Mr.doob 已提交
82 83 84
		this.x = v.x;
		this.y = v.y;
		this.z = v.z;
M
Mr.doob 已提交
85

86
		return this;
M
Mr.doob 已提交
87

88
	},
89

90 91 92 93 94 95 96 97
	add: function ( v, w ) {

		if ( w !== undefined ) {

			console.warn( 'DEPRECATED: Vector3\'s .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
			return this.addVectors( v, w );

		}
M
Mr.doob 已提交
98

M
Mr.doob 已提交
99 100 101
		this.x += v.x;
		this.y += v.y;
		this.z += v.z;
102

B
Ben Nolan 已提交
103 104
		return this;

105
	},
106

107
	addScalar: function ( s ) {
M
Mr.doob 已提交
108

M
Mr.doob 已提交
109 110 111
		this.x += s;
		this.y += s;
		this.z += s;
112

B
Ben Nolan 已提交
113 114
		return this;

115
	},
116

117
	addVectors: function ( a, b ) {
118

119 120 121
		this.x = a.x + b.x;
		this.y = a.y + b.y;
		this.z = a.z + b.z;
122

123
		return this;
M
Mr.doob 已提交
124

125
	},
126

127 128 129 130 131 132 133 134
	sub: function ( v, w ) {

		if ( w !== undefined ) {

			console.warn( 'DEPRECATED: Vector3\'s .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
			return this.subVectors( v, w );

		}
135

M
Mr.doob 已提交
136 137 138
		this.x -= v.x;
		this.y -= v.y;
		this.z -= v.z;
139

B
Ben Nolan 已提交
140 141
		return this;

142
	},
143

144
	subVectors: function ( a, b ) {
145

146 147 148
		this.x = a.x - b.x;
		this.y = a.y - b.y;
		this.z = a.z - b.z;
149

150
		return this;
M
Mr.doob 已提交
151

152
	},
153

154 155 156 157 158 159 160 161
	multiply: function ( v, w ) {

		if ( w !== undefined ) {

			console.warn( 'DEPRECATED: Vector3\'s .multiply() now only accepts one argument. Use .multiplyVectors( a, b ) instead.' );
			return this.multiplyVectors( v, w );

		}
162

M
Mr.doob 已提交
163 164
		this.x *= v.x;
		this.y *= v.y;
N
Nico Kruithof 已提交
165
		this.z *= v.z;
M
Mr.doob 已提交
166 167 168 169 170

		return this;

	},

171
	multiplyScalar: function ( s ) {
M
Mr.doob 已提交
172

M
Mr.doob 已提交
173 174 175
		this.x *= s;
		this.y *= s;
		this.z *= s;
176

B
Ben Nolan 已提交
177 178
		return this;

179
	},
180

181 182 183 184 185 186 187 188 189 190
	multiplyVectors: function ( a, b ) {

		this.x = a.x * b.x;
		this.y = a.y * b.y;
		this.z = a.z * b.z;

		return this;

	},

191
	applyMatrix3: function ( m ) {
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206

		var x = this.x;
		var y = this.y;
		var z = this.z;

		var e = m.elements;

		this.x = e[0] * x + e[3] * y + e[6] * z;
		this.y = e[1] * x + e[4] * y + e[7] * z;
		this.z = e[2] * x + e[5] * y + e[8] * z;

		return this;

	},

207
	applyMatrix4: function ( m ) {
208

209 210 211
		// input: THREE.Matrix4 affine matrix

		var x = this.x, y = this.y, z = this.z;
212 213 214

		var e = m.elements;

215 216 217
		this.x = e[0] * x + e[4] * y + e[8]  * z + e[12];
		this.y = e[1] * x + e[5] * y + e[9]  * z + e[13];
		this.z = e[2] * x + e[6] * y + e[10] * z + e[14];
218 219 220 221 222

		return this;

	},

223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239
	applyProjection: function ( m ) {

		// input: THREE.Matrix4 projection matrix

		var x = this.x, y = this.y, z = this.z;

		var e = m.elements;
		var d = 1 / ( e[3] * x + e[7] * y + e[11] * z + e[15] ); // perspective divide

		this.x = ( e[0] * x + e[4] * y + e[8]  * z + e[12] ) * d;
		this.y = ( e[1] * x + e[5] * y + e[9]  * z + e[13] ) * d;
		this.z = ( e[2] * x + e[6] * y + e[10] * z + e[14] ) * d;

		return this;

	},

240
	applyQuaternion: function ( q ) {
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

		var x = this.x;
		var y = this.y;
		var z = this.z;

		var qx = q.x;
		var qy = q.y;
		var qz = q.z;
		var qw = q.w;

		// calculate quat * vector

		var ix =  qw * x + qy * z - qz * y;
		var iy =  qw * y + qz * x - qx * z;
		var iz =  qw * z + qx * y - qy * x;
		var iw = -qx * x - qy * y - qz * z;

		// calculate result * inverse quat

		this.x = ix * qw + iw * -qx + iy * -qz - iz * -qy;
		this.y = iy * qw + iw * -qy + iz * -qx - ix * -qz;
		this.z = iz * qw + iw * -qz + ix * -qy - iy * -qx;

		return this;

	},

268
	applyEuler: function () {
269

270
		var q1 = new THREE.Quaternion();
M
Mr.doob 已提交
271

272
		return function ( v, eulerOrder ) {
273

274
			var quaternion = q1.setFromEuler( v, eulerOrder );
275

276
			this.applyQuaternion( quaternion );
277

278
			return this;
279

280
		};
281

282
	}(),
283

284
	applyAxisAngle: function () {
285

286
		var q1 = new THREE.Quaternion();
M
Mr.doob 已提交
287

288
		return function ( axis, angle ) {
289

290 291 292 293 294 295 296 297 298
			var quaternion = q1.setFromAxisAngle( axis, angle );

			this.applyQuaternion( quaternion );

			return this;

		};

	}(),
299

300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318
	transformDirection: function ( m ) {

		// input: THREE.Matrix4 affine matrix
		// vector interpreted as a direction

		var x = this.x, y = this.y, z = this.z;

		var e = m.elements;

		this.x = e[0] * x + e[4] * y + e[8]  * z;
		this.y = e[1] * x + e[5] * y + e[9]  * z;
		this.z = e[2] * x + e[6] * y + e[10] * z;

		this.normalize();

		return this;

	},

319
	divide: function ( v ) {
320

321 322 323 324 325
		this.x /= v.x;
		this.y /= v.y;
		this.z /= v.z;

		return this;
M
Mr.doob 已提交
326

M
Mr.doob 已提交
327
	},
328

329
	divideScalar: function ( s ) {
330

B
Ben Houston 已提交
331
		if ( s !== 0 ) {
332

M
Mr.doob 已提交
333 334 335
			this.x /= s;
			this.y /= s;
			this.z /= s;
M
Mr.doob 已提交
336

M
Mr.doob 已提交
337
		} else {
M
Mr.doob 已提交
338

339 340 341
			this.x = 0;
			this.y = 0;
			this.z = 0;
342

M
Mr.doob 已提交
343
		}
344

B
Ben Nolan 已提交
345 346
		return this;

347
	},
348

349
	min: function ( v ) {
350

A
alteredq 已提交
351 352
		if ( this.x > v.x ) {

353
			this.x = v.x;
A
alteredq 已提交
354

355
		}
A
alteredq 已提交
356 357 358

		if ( this.y > v.y ) {

359
			this.y = v.y;
A
alteredq 已提交
360

361
		}
A
alteredq 已提交
362 363 364

		if ( this.z > v.z ) {

365
			this.z = v.z;
A
alteredq 已提交
366

367
		}
368 369 370 371 372

		return this;

	},

373
	max: function ( v ) {
374

A
alteredq 已提交
375 376
		if ( this.x < v.x ) {

377
			this.x = v.x;
A
alteredq 已提交
378

379
		}
A
alteredq 已提交
380 381 382

		if ( this.y < v.y ) {

383
			this.y = v.y;
A
alteredq 已提交
384

385
		}
A
alteredq 已提交
386 387 388

		if ( this.z < v.z ) {

389
			this.z = v.z;
A
alteredq 已提交
390

391
		}
392 393 394 395

		return this;

	},
M
Mr.doob 已提交
396

397
	clamp: function ( min, max ) {
398 399 400

		// This function assumes min < max, if this assumption isn't true it will not operate correctly

A
alteredq 已提交
401 402
		if ( this.x < min.x ) {

403
			this.x = min.x;
A
alteredq 已提交
404 405 406

		} else if ( this.x > max.x ) {

407
			this.x = max.x;
A
alteredq 已提交
408

409 410
		}

A
alteredq 已提交
411 412
		if ( this.y < min.y ) {

413
			this.y = min.y;
A
alteredq 已提交
414 415 416

		} else if ( this.y > max.y ) {

417
			this.y = max.y;
A
alteredq 已提交
418

419 420
		}

A
alteredq 已提交
421 422
		if ( this.z < min.z ) {

423
			this.z = min.z;
A
alteredq 已提交
424 425 426

		} else if ( this.z > max.z ) {

427
			this.z = max.z;
A
alteredq 已提交
428

429 430 431
		}

		return this;
A
alteredq 已提交
432

433 434
	},

435
	negate: function () {
M
Mr.doob 已提交
436

M
Mr.doob 已提交
437
		return this.multiplyScalar( - 1 );
B
Ben Nolan 已提交
438

439
	},
440

441
	dot: function ( v ) {
M
Mr.doob 已提交
442

M
Mr.doob 已提交
443
		return this.x * v.x + this.y * v.y + this.z * v.z;
M
Mr.doob 已提交
444

M
Mr.doob 已提交
445
	},
M
Mr.doob 已提交
446

447
	lengthSq: function () {
M
Mr.doob 已提交
448

M
Mr.doob 已提交
449
		return this.x * this.x + this.y * this.y + this.z * this.z;
M
Mr.doob 已提交
450 451 452

	},

453
	length: function () {
M
Mr.doob 已提交
454

455
		return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z );
M
Mr.doob 已提交
456

M
Mr.doob 已提交
457
	},
458

459
	lengthManhattan: function () {
460

461
		return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z );
A
alteredq 已提交
462

463 464
	},

465
	normalize: function () {
466

M
Mr.doob 已提交
467
		return this.divideScalar( this.length() );
468

469
	},
470

471
	setLength: function ( l ) {
472

473
		var oldLength = this.length();
M
Mr.doob 已提交
474

B
Ben Houston 已提交
475
		if ( oldLength !== 0 && l !== oldLength  ) {
476 477 478 479 480

			this.multiplyScalar( l / oldLength );
		}

		return this;
481

482
	},
483

484
	lerp: function ( v, alpha ) {
485 486 487 488 489 490 491 492

		this.x += ( v.x - this.x ) * alpha;
		this.y += ( v.y - this.y ) * alpha;
		this.z += ( v.z - this.z ) * alpha;

		return this;

	},
493

494 495 496 497 498 499 500 501
	cross: function ( v, w ) {

		if ( w !== undefined ) {

			console.warn( 'DEPRECATED: Vector3\'s .cross() now only accepts one argument. Use .crossVectors( a, b ) instead.' );
			return this.crossVectors( v, w );

		}
502

503
		var x = this.x, y = this.y, z = this.z;
504

505 506 507
		this.x = y * v.z - z * v.y;
		this.y = z * v.x - x * v.z;
		this.z = x * v.y - y * v.x;
508

509
		return this;
510 511 512

	},

513 514 515 516 517 518 519 520 521 522
	crossVectors: function ( a, b ) {

		this.x = a.y * b.z - a.z * b.y;
		this.y = a.z * b.x - a.x * b.z;
		this.z = a.x * b.y - a.y * b.x;

		return this;

	},

W
Wilt 已提交
523
	angleTo: function ( v ) {
M
Mr.doob 已提交
524

W
Wilt 已提交
525
		return Math.acos( this.dot( v ) / this.length() / v.length() );
M
Mr.doob 已提交
526 527

	},
W
Wilt 已提交
528

529
	distanceTo: function ( v ) {
530

M
Mr.doob 已提交
531
		return Math.sqrt( this.distanceToSquared( v ) );
532

M
Mr.doob 已提交
533 534
	},

535
	distanceToSquared: function ( v ) {
M
Mr.doob 已提交
536

M
Mr.doob 已提交
537 538 539 540
		var dx = this.x - v.x;
		var dy = this.y - v.y;
		var dz = this.z - v.z;

541
		return dx * dx + dy * dy + dz * dz;
M
Mr.doob 已提交
542

543
	},
M
Mr.doob 已提交
544

M
Mr.doob 已提交
545
	getPositionFromMatrix: function ( m ) {
M
Mr.doob 已提交
546

547 548 549
		this.x = m.elements[12];
		this.y = m.elements[13];
		this.z = m.elements[14];
550

551 552
		return this;

553 554
	},

W
WestLangley 已提交
555 556 557
	setEulerFromRotationMatrix: function ( m, order ) {

		// assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
M
Mr.doob 已提交
558

W
WestLangley 已提交
559
		// clamp, to handle numerical problems
M
Mr.doob 已提交
560 561 562 563 564 565

		function clamp( x ) {

			return Math.min( Math.max( x, -1 ), 1 );

		}
566 567 568 569 570 571 572 573 574

		var te = m.elements;
		var m11 = te[0], m12 = te[4], m13 = te[8];
		var m21 = te[1], m22 = te[5], m23 = te[9];
		var m31 = te[2], m32 = te[6], m33 = te[10];

		if ( order === undefined || order === 'XYZ' ) {

			this.y = Math.asin( clamp( m13 ) );
M
Mr.doob 已提交
575

576
			if ( Math.abs( m13 ) < 0.99999 ) {
M
Mr.doob 已提交
577

578 579
				this.x = Math.atan2( - m23, m33 );
				this.z = Math.atan2( - m12, m11 );
M
Mr.doob 已提交
580

581
			} else {
M
Mr.doob 已提交
582

583
				this.x = Math.atan2( m32, m22 );
584
				this.z = 0;
M
Mr.doob 已提交
585

586 587 588
			}

		} else if ( order === 'YXZ' ) {
M
Mr.doob 已提交
589

590
			this.x = Math.asin( - clamp( m23 ) );
M
Mr.doob 已提交
591

592
			if ( Math.abs( m23 ) < 0.99999 ) {
M
Mr.doob 已提交
593

594 595
				this.y = Math.atan2( m13, m33 );
				this.z = Math.atan2( m21, m22 );
M
Mr.doob 已提交
596

597
			} else {
M
Mr.doob 已提交
598

599 600
				this.y = Math.atan2( - m31, m11 );
				this.z = 0;
M
Mr.doob 已提交
601

602
			}
M
Mr.doob 已提交
603

604
		} else if ( order === 'ZXY' ) {
M
Mr.doob 已提交
605

606
			this.x = Math.asin( clamp( m32 ) );
M
Mr.doob 已提交
607

608
			if ( Math.abs( m32 ) < 0.99999 ) {
M
Mr.doob 已提交
609

610 611
				this.y = Math.atan2( - m31, m33 );
				this.z = Math.atan2( - m12, m22 );
M
Mr.doob 已提交
612

613
			} else {
M
Mr.doob 已提交
614

615
				this.y = 0;
616
				this.z = Math.atan2( m21, m11 );
M
Mr.doob 已提交
617

618 619 620
			}

		} else if ( order === 'ZYX' ) {
M
Mr.doob 已提交
621

622
			this.y = Math.asin( - clamp( m31 ) );
M
Mr.doob 已提交
623

624
			if ( Math.abs( m31 ) < 0.99999 ) {
M
Mr.doob 已提交
625

626 627
				this.x = Math.atan2( m32, m33 );
				this.z = Math.atan2( m21, m11 );
M
Mr.doob 已提交
628

629
			} else {
M
Mr.doob 已提交
630

631 632
				this.x = 0;
				this.z = Math.atan2( - m12, m22 );
M
Mr.doob 已提交
633

634
			}
M
Mr.doob 已提交
635

636
		} else if ( order === 'YZX' ) {
M
Mr.doob 已提交
637

638
			this.z = Math.asin( clamp( m21 ) );
M
Mr.doob 已提交
639

640
			if ( Math.abs( m21 ) < 0.99999 ) {
M
Mr.doob 已提交
641

642 643
				this.x = Math.atan2( - m23, m22 );
				this.y = Math.atan2( - m31, m11 );
M
Mr.doob 已提交
644

645
			} else {
M
Mr.doob 已提交
646

647
				this.x = 0;
648
				this.y = Math.atan2( m13, m33 );
M
Mr.doob 已提交
649

650
			}
M
Mr.doob 已提交
651

652
		} else if ( order === 'XZY' ) {
M
Mr.doob 已提交
653

654
			this.z = Math.asin( - clamp( m12 ) );
M
Mr.doob 已提交
655

656
			if ( Math.abs( m12 ) < 0.99999 ) {
M
Mr.doob 已提交
657

658 659
				this.x = Math.atan2( m32, m22 );
				this.y = Math.atan2( m13, m11 );
M
Mr.doob 已提交
660

661
			} else {
M
Mr.doob 已提交
662

663
				this.x = Math.atan2( - m23, m33 );
664
				this.y = 0;
M
Mr.doob 已提交
665

666
			}
M
Mr.doob 已提交
667

668
		}
M
Mr.doob 已提交
669

670 671 672 673
		return this;

	},

W
WestLangley 已提交
674 675 676
	setEulerFromQuaternion: function ( q, order ) {

		// q is assumed to be normalized
M
Mr.doob 已提交
677

W
WestLangley 已提交
678
		// clamp, to handle numerical problems
M
Mr.doob 已提交
679 680 681 682 683 684 685 686

		function clamp( x ) {

			return Math.min( Math.max( x, -1 ), 1 );

		}

		// http://www.mathworks.com/matlabcentral/fileexchange/20696-function-to-convert-between-dcm-euler-angles-quaternions-and-euler-vectors/content/SpinCalc.m
M
Mr.doob 已提交
687

M
Mr.doob 已提交
688 689 690 691
		var sqx = q.x * q.x;
		var sqy = q.y * q.y;
		var sqz = q.z * q.z;
		var sqw = q.w * q.w;
692 693 694 695 696 697

		if ( order === undefined || order === 'XYZ' ) {

			this.x = Math.atan2( 2 * ( q.x * q.w - q.y * q.z ), ( sqw - sqx - sqy + sqz ) );
			this.y = Math.asin(  clamp( 2 * ( q.x * q.z + q.y * q.w ) ) );
			this.z = Math.atan2( 2 * ( q.z * q.w - q.x * q.y ), ( sqw + sqx - sqy - sqz ) );
M
Mr.doob 已提交
698

699
		} else if ( order ===  'YXZ' ) {
M
Mr.doob 已提交
700

701 702 703
			this.x = Math.asin(  clamp( 2 * ( q.x * q.w - q.y * q.z ) ) );
			this.y = Math.atan2( 2 * ( q.x * q.z + q.y * q.w ), ( sqw - sqx - sqy + sqz ) );
			this.z = Math.atan2( 2 * ( q.x * q.y + q.z * q.w ), ( sqw - sqx + sqy - sqz ) );
M
Mr.doob 已提交
704

705
		} else if ( order === 'ZXY' ) {
M
Mr.doob 已提交
706

707 708 709
			this.x = Math.asin(  clamp( 2 * ( q.x * q.w + q.y * q.z ) ) );
			this.y = Math.atan2( 2 * ( q.y * q.w - q.z * q.x ), ( sqw - sqx - sqy + sqz ) );
			this.z = Math.atan2( 2 * ( q.z * q.w - q.x * q.y ), ( sqw - sqx + sqy - sqz ) );
M
Mr.doob 已提交
710

711
		} else if ( order === 'ZYX' ) {
M
Mr.doob 已提交
712

713 714 715
			this.x = Math.atan2( 2 * ( q.x * q.w + q.z * q.y ), ( sqw - sqx - sqy + sqz ) );
			this.y = Math.asin(  clamp( 2 * ( q.y * q.w - q.x * q.z ) ) );
			this.z = Math.atan2( 2 * ( q.x * q.y + q.z * q.w ), ( sqw + sqx - sqy - sqz ) );
M
Mr.doob 已提交
716

717
		} else if ( order === 'YZX' ) {
M
Mr.doob 已提交
718

719 720 721
			this.x = Math.atan2( 2 * ( q.x * q.w - q.z * q.y ), ( sqw - sqx + sqy - sqz ) );
			this.y = Math.atan2( 2 * ( q.y * q.w - q.x * q.z ), ( sqw + sqx - sqy - sqz ) );
			this.z = Math.asin(  clamp( 2 * ( q.x * q.y + q.z * q.w ) ) );
M
Mr.doob 已提交
722

723
		} else if ( order === 'XZY' ) {
M
Mr.doob 已提交
724

725 726 727
			this.x = Math.atan2( 2 * ( q.x * q.w + q.y * q.z ), ( sqw - sqx + sqy - sqz ) );
			this.y = Math.atan2( 2 * ( q.x * q.z + q.y * q.w ), ( sqw + sqx - sqy - sqz ) );
			this.z = Math.asin(  clamp( 2 * ( q.z * q.w - q.x * q.y ) ) );
M
Mr.doob 已提交
728

A
alteredq 已提交
729
		}
M
Mr.doob 已提交
730

W
WestLangley 已提交
731
		return this;
A
alteredq 已提交
732 733

	},
734

M
Mr.doob 已提交
735 736
	getScaleFromMatrix: function ( m ) {

737 738 739
		var sx = this.set( m.elements[0], m.elements[1], m.elements[2] ).length();
		var sy = this.set( m.elements[4], m.elements[5], m.elements[6] ).length();
		var sz = this.set( m.elements[8], m.elements[9], m.elements[10] ).length();
M
Mr.doob 已提交
740

741 742 743
		this.x = sx;
		this.y = sy;
		this.z = sz;
M
Mr.doob 已提交
744

745
		return this;
M
Mr.doob 已提交
746 747 748
	},

	equals: function ( v ) {
749 750 751

		return ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) );

752 753
	},

M
Mr.doob 已提交
754 755 756 757
	clone: function () {

		return new THREE.Vector3( this.x, this.y, this.z );

758
	}
759

M
Mr.doob 已提交
760
} );