Vector3.html 14.0 KB
Newer Older
1 2 3
<!DOCTYPE html>
<html lang="en">
	<head>
G
gero3 已提交
4
		<meta charset="utf-8" />
M
Mr.doob 已提交
5 6 7 8
		<base href="../../" />
		<script src="list.js"></script>
		<script src="page.js"></script>
		<link type="text/css" rel="stylesheet" href="page.css" />
9 10 11
	</head>
	<body>
		<h1>[name]</h1>
M
Mr.doob 已提交
12

13
		<div class="desc">3D vector.</div>
M
Mr.doob 已提交
14 15


16
		<h2>Example</h2>
M
Mr.doob 已提交
17

18 19
		<code>var a = new THREE.Vector3( 1, 0, 0 );
		var b = new THREE.Vector3( 0, 1, 0 );
M
Mr.doob 已提交
20

21
		var c = new THREE.Vector3();
22
		c.crossVectors( a, b );
23
		</code>
M
Mr.doob 已提交
24 25


26
		<h2>Constructor</h2>
M
Mr.doob 已提交
27

C
cjshannon 已提交
28

29
		<h3>[name]( [page:Float x], [page:Float y], [page:Float z] )</h3>
C
cjshannon 已提交
30
		<div>
31 32 33
		x -- [page:Float] the vector's x value <br />
		y -- [page:Float] the vector's y value <br />
		z -- [page:Float] the vector's z value
C
cjshannon 已提交
34 35
		</div>
		<div>
36
		A 3 dimensional vector
C
cjshannon 已提交
37
		</div>
M
Mr.doob 已提交
38 39


40
		<h2>Properties</h2>
M
Mr.doob 已提交
41

42
		<h3>[property:Float x]</h3>
M
Mr.doob 已提交
43

44
		<h3>[property:Float y]</h3>
M
Mr.doob 已提交
45

46
		<h3>[property:Float z]</h3>
M
Mr.doob 已提交
47 48


49
		<h2>Methods</h2>
M
Mr.doob 已提交
50

51
		<h3>[method:Vector3 set]( [page:Float x], [page:Float y], [page:Float z] ) [page:Vector3 this]</h3>
52 53 54
		<div>
		Sets value of this vector.
		</div>
M
Mr.doob 已提交
55

56
		<h3>[method:Vector3 setX]( [page:Float x] ) [page:Vector3 this]</h3>
57 58 59
		<div>
		Sets x value of this vector.
		</div>
M
Mr.doob 已提交
60

61
		<h3>[method:Vector3 setY]( [page:Float y] ) [page:Vector3 this]</h3>
62 63 64
		<div>
		Sets y value of this vector.
		</div>
M
Mr.doob 已提交
65

66
		<h3>[method:Vector3 setZ]( [page:Float z] ) [page:Vector3 this]</h3>
67 68 69 70
		<div>
		Sets z value of this vector.
		</div>

A
aardgoose 已提交
71 72 73 74 75 76 77 78
		<h3>[method:Vector3 setScalar]( [page:Float scalar] ) [page:Vector3 this]</h3>
		<div>
		scalar -- [page:Float]
		</div>
		<div>
		set all component values of this vector to *scalar*.
		</div>

79
		<h3>[method:Vector3 copy]( [page:Vector3 v] ) [page:Vector3 this]</h3>
80 81 82 83
		<div>
		Copies value of *v* to this vector.
		</div>

T
tschw 已提交
84 85 86 87 88 89 90 91 92
		<h3>[method:Vector3 fromArray]( [page:Array array], [page:Integer offset] ) [page:Vector3 this]</h3>
		<div>
		array -- The source array in the form [x, y, z].<br />
		offset -- An optional offset into the array.
		</div>
		<div>
		Sets the vector's components based on an array formatted like [x, y, z]
		</div>

93
		<h3>[method:Vector3 add]( [page:Vector3 v] ) [page:Vector3 this]</h3>
94
		<div>
95
		Adds *v* to this vector.
96 97
		</div>

98
		<h3>[method:Vector3 addVectors]( [page:Vector3 a], [page:Vector3 b] ) [page:Vector3 this]</h3>
99
		<div>
100
		Sets this vector to *a + b*.
101 102
		</div>

G
gero3 已提交
103 104 105 106 107
		<h3>[method:Vector3 addScaledVector]( [page:Vector3 v], [page:Float s] ) [page:Vector3 this]</h3>
		<div>
		Adds the multiple of v and s to this vector.
		</div>

108
		<h3>[method:Vector3 sub]( [page:Vector3 v] ) [page:Vector3 this]</h3>
109
		<div>
110
		Subtracts *v* from this vector.
111 112
		</div>

113
		<h3>[method:Vector3 subVectors]( [page:Vector3 a], [page:Vector3 b] ) [page:Vector3 this]</h3>
114
		<div>
115
		Sets this vector to *a - b*.
116 117
		</div>

118
		<h3>[method:Vector3 multiplyScalar]( [page:Float s] ) [page:Vector3 this]</h3>
119 120 121
		<div>
		Multiplies this vector by scalar *s*.
		</div>
M
Mr.doob 已提交
122

123
		<h3>[method:Vector3 divideScalar]( [page:Float s] ) [page:Vector3 this]</h3>
124 125 126 127 128
		<div>
		Divides this vector by scalar *s*.<br />
		Set vector to *( 0, 0, 0 )* if *s == 0*.
		</div>

129
		<h3>[method:Vector3 negate]() [page:Vector3 this]</h3>
130 131 132 133
		<div>
		Inverts this vector.
		</div>

T
tschw 已提交
134
		<h3>[method:Float dot]( [page:Vector3 v] ) [page:Vector3 this]</h3>
135 136 137
		<div>
		Computes dot product of this vector and *v*.
		</div>
M
Mr.doob 已提交
138

T
tschw 已提交
139
		<h3>[method:Float lengthSq]() [page:Vector3 this]</h3>
140
		<div>
W
WestLangley 已提交
141
		Computes the squared length of this vector.
142
		</div>
M
Mr.doob 已提交
143

T
tschw 已提交
144
		<h3>[method:Float length]() [page:Vector3 this]</h3>
145
		<div>
W
WestLangley 已提交
146
		Computes the length of this vector.
147
		</div>
M
Mr.doob 已提交
148

T
tschw 已提交
149
		<h3>[method:Float lengthManhattan]() [page:Vector3 this]</h3>
150
		<div>
W
WestLangley 已提交
151
		Computes the Manhattan length of this vector.<br />
152 153 154
		[link:http://en.wikipedia.org/wiki/Taxicab_geometry]
		</div>

155
		<h3>[method:Vector3 normalize]() [page:Vector3 this]</h3>
156
		<div>
157
		Normalizes this vector. Transforms this Vector into a Unit vector by dividing the vector by its length.
158 159
		</div>

W
WestLangley 已提交
160
		<h3>[method:Float distanceTo]( [page:Vector3 v] )</h3>
161
		<div>
W
WestLangley 已提交
162
		Computes the distance from this vector to *v*.
163 164
		</div>

W
WestLangley 已提交
165
		<h3>[method:Float distanceToSquared]( [page:Vector3 v] )</h3>
166
		<div>
W
WestLangley 已提交
167 168 169 170 171 172
		Computes the squared distance from this vector to *v*.
		</div>

		<h3>[method:Float distanceToManhattan]( [page:Vector3 v] )</h3>
		<div>
		Computes the Manhattan distance from this vector to *v*.
173 174
		</div>

175
		<h3>[method:Vector3 setLength]( [page:Float l] ) [page:Vector3 this]</h3>
176 177 178 179
		<div>
		Normalizes this vector and multiplies it by *l*.
		</div>

180
		<h3>[method:Vector3 cross]( [page:Vector3 v] ) [page:Vector3 this]</h3>
181
		<div>
182
		Sets this vector to cross product of itself and *v*.
183 184
		</div>

185
		<h3>[method:Vector3 crossVectors]( [page:Vector3 a], [page:Vector3 b] ) [page:Vector3 this]</h3>
186
		<div>
187
		Sets this vector to cross product of *a* and *b*.
188 189
		</div>

190
		<h3>[method:Vector3 setFromMatrixPosition]( [page:Matrix4 m] ) [page:Vector3 this]</h3>
191 192 193 194
		<div>
		Sets this vector extracting position from matrix transform.
		</div>

195
		<h3>[method:Vector3 setFromMatrixScale]( [page:Matrix4 m] ) [page:Vector3 this]</h3>
196 197 198 199
		<div>
		Sets this vector extracting scale from matrix transform.
		</div>

A
aardgoose 已提交
200 201 202 203 204
		<h3>[method:Vector3 setFromSpherical]( [page:Spherical s] ) [page:Vector3 this]</h3>
		<div>
		Sets this vector from the spherical coordinates *s*.
		</div>

M
Mugen87 已提交
205 206 207 208 209
		<h3>[method:Vector3 setFromCylindrical]( [page:Cylindrical c] ) [page:Vector3 this]</h3>
		<div>
		Sets this vector from the cylindrical coordinates *c*.
		</div>

T
tschw 已提交
210
		<h3>[method:Vector3 clamp]( [page:Vector3 min], [page:Vector3 max] ) [page:Vector3 this]</h3>
C
cjshannon 已提交
211
		<div>
212 213
		min -- [page:Vector3] <br />
		max -- [page:Vector3]
C
cjshannon 已提交
214 215
		</div>
		<div>
G
Greg Tatum 已提交
216
		If this vector's x, y or z value is greater than the max vector's x, y or z value, it is replaced by the corresponding value. <br /><br />
217
		If this vector's x, y or z value is less than the min vector's x, y or z value, it is replaced by the corresponding value.
C
cjshannon 已提交
218 219
		</div>

T
tschw 已提交
220
		<h3>[method:Vector3 clampScalar]( [page:Float min], [page:Float max] ) [page:Vector3 this]</h3>
221 222 223 224 225
		<div>
		min -- [page:Float] the minimum value the components will be clamped to <br />
		max -- [page:Float] the maximum value the components will be clamped to
		</div>
		<div>
226 227
		If this vector's x, y or z values are greater than the max value, they are replaced by the max value. <br /><br />
		If this vector's x, y or z values are less than the min value, they are replaced by the min value.
228 229
		</div>

T
tschw 已提交
230
		<h3>[method:Vector3 clampLength]( [page:Float min], [page:Float max] ) [page:Vector3 this]</h3>
231 232 233 234 235 236 237 238 239
		<div>
		min -- [page:Float] the minimum value the length will be clamped to <br />
		max -- [page:Float] the maximum value the length will be clamped to
		</div>
		<div>
		If this vector's length is greater than the max value, it is replaced by the max value. <br /><br />
		If this vector's length is less than the min value, it is replaced by the min value.
		</div>

T
tschw 已提交
240
		<h3>[method:Vector3 floor]() [page:Vector3 this]</h3>
241 242 243 244
		<div>
		The components of the vector are rounded downwards (towards negative infinity) to an integer value.
		</div>

T
tschw 已提交
245
		<h3>[method:Vector3 ceil]() [page:Vector3 this]</h3>
246 247 248 249
		<div>
		The components of the vector are rounded upwards (towards positive infinity) to an integer value.
		</div>

T
tschw 已提交
250
		<h3>[method:Vector3 round]() [page:Vector3 this]</h3>
251 252 253 254
		<div>
		The components of the vector are rounded towards the nearest integer value.
		</div>

T
tschw 已提交
255
		<h3>[method:Vector3 roundToZero]() [page:Vector3 this]</h3>
256 257 258 259
		<div>
		The components of the vector are rounded towards zero (up if negative, down if positive) to an integer value.
		</div>

T
tschw 已提交
260
		<h3>[method:Vector3 applyMatrix3]( [page:Matrix3 m] ) [page:Vector3 this]</h3>
C
cjshannon 已提交
261
		<div>
262
		m -- [page:Matrix3]
C
cjshannon 已提交
263 264
		</div>
		<div>
265
		Multiplies this vector times a 3 x 3 matrix.
C
cjshannon 已提交
266 267
		</div>

T
tschw 已提交
268
		<h3>[method:Vector3 applyMatrix4]( [page:Matrix3 m] ) [page:Vector3 this]</h3>
C
cjshannon 已提交
269
		<div>
G
Greg Tatum 已提交
270
		m -- [page:Matrix4]
C
cjshannon 已提交
271 272
		</div>
		<div>
273
		Multiplies this vector by 4 x 3 subset of a Matrix4.
C
cjshannon 已提交
274 275
		</div>

T
tschw 已提交
276
		<h3>[method:Vector3 projectOnPlane]( [page:Vector3 planeNormal] ) [page:Vector3 this]</h3>
C
cjshannon 已提交
277
		<div>
G
Greg Tatum 已提交
278
		planeNormal -- [page:Vector3 planeNormal] A vector representing a plane normal.
C
cjshannon 已提交
279 280
		</div>
		<div>
281
		Projects this vector onto a plane by subtracting this vector projected onto the plane's normal from this vector.
C
cjshannon 已提交
282 283
		</div>

T
tschw 已提交
284
		<h3>[method:Vector3 projectOnVector]( [page:Vector3] ) [page:Vector3 this]</h3>
C
cjshannon 已提交
285
		<div>
G
Greg Tatum 已提交
286
		vector -- [page:Vector3]
C
cjshannon 已提交
287 288
		</div>
		<div>
289
		Projects this vector onto another vector.
C
cjshannon 已提交
290 291
		</div>

T
tschw 已提交
292
		<h3>[method:Vector3 addScalar]( [page:Float] ) [page:Vector3 this]</h3>
C
cjshannon 已提交
293
		<div>
G
Greg Tatum 已提交
294
		s -- [page:Float]
C
cjshannon 已提交
295 296
		</div>
		<div>
297
		Adds a s to this vector.
C
cjshannon 已提交
298 299
		</div>

T
tschw 已提交
300
		<h3>[method:Vector3 divide]( [page:Vector3 v] ) [page:Vector3 this]</h3>
C
cjshannon 已提交
301
		<div>
G
Greg Tatum 已提交
302
		v -- [page:Vector3]
C
cjshannon 已提交
303 304
		</div>
		<div>
305
		Divides this vector by vector v.
C
cjshannon 已提交
306 307
		</div>

T
tschw 已提交
308
		<h3>[method:Vector3 min]( [page:Vector3 v] ) [page:Vector3 this]</h3>
C
cjshannon 已提交
309
		<div>
G
Greg Tatum 已提交
310
		v -- [page:Vector3]
C
cjshannon 已提交
311 312
		</div>
		<div>
313
		If this vector's x, y, or z value is greater than vector v's x, y, or z value, that value is replaced by the corresponding vector v value.
C
cjshannon 已提交
314 315
		</div>

T
tschw 已提交
316
		<h3>[method:Vector3 max]( [page:Vector3 v] ) [page:Vector3 this]</h3>
G
Greg Tatum 已提交
317 318 319 320
		<div>
		v -- [page:Vector3]
		</div>
		<div>
321
		If this vector's x, y, or z value is less than vector v's x, y, or z value, that value is replaced by the corresponding vector v value.
G
Greg Tatum 已提交
322 323
		</div>

324
		<h3>[method:null setComponent]( [page:Integer index], [page:Float value] ) [page:Vector3 this]</h3>
C
cjshannon 已提交
325
		<div>
326
		index -- 0, 1, or 2 <br />
G
Greg Tatum 已提交
327
		value -- [page:Float]
C
cjshannon 已提交
328 329
		</div>
		<div>
330 331 332
		If index equals 0 the method sets this vector's x value to value <br />
		If index equals 1 the method sets this vector's y value to value <br />
		If index equals 2 the method sets this vector's z value to value
C
cjshannon 已提交
333 334
		</div>

T
tschw 已提交
335
		<h3>[method:Vector3 transformDirection]( [page:Matrix4 m] ) [page:Vector3 this]</h3>
C
cjshannon 已提交
336
		<div>
G
Greg Tatum 已提交
337
		m -- [page:Matrix4]
C
cjshannon 已提交
338 339
		</div>
		<div>
G
Greg Tatum 已提交
340
		Transforms the direction of this vector by a matrix (a 3 x 3 subset of a Matrix4) and then normalizes the result.
C
cjshannon 已提交
341 342
		</div>

T
tschw 已提交
343
		<h3>[method:Vector3 multiplyVectors]( [page:Vector3 a], [page:Vector3 b] ) [page:Vector3 this]</h3>
C
cjshannon 已提交
344
		<div>
G
Greg Tatum 已提交
345 346
		a -- [page:Vector3] <br />
		b -- [page:Vector3]
C
cjshannon 已提交
347 348
		</div>
		<div>
G
Greg Tatum 已提交
349
		Sets this vector equal to the result of multiplying vector a by vector b.
C
cjshannon 已提交
350 351
		</div>

T
tschw 已提交
352
		<h3>[method:Float getComponent]( [page:Integer index] ) [page:Vector3 this]</h3>
C
cjshannon 已提交
353
		<div>
G
Greg Tatum 已提交
354
		index -- [page:Integer] 0, 1, or 2
C
cjshannon 已提交
355 356
		</div>
		<div>
M
Mr.doob 已提交
357

G
Greg Tatum 已提交
358
		Returns the value of the vector component x, y, or z by an index. <br /><br />
M
Mr.doob 已提交
359

G
Greg Tatum 已提交
360 361 362
		Index 0: x <br />
		Index 1: y <br />
		Index 2: z <br />
C
cjshannon 已提交
363 364
		</div>

T
tschw 已提交
365
		<h3>[method:Vector3 applyAxisAngle]( [page:Vector3 axis], [page:Float angle] ) [page:Vector3 this]</h3>
C
cjshannon 已提交
366
		<div>
G
Greg Tatum 已提交
367 368
		axis -- A normalized [page:Vector3] <br />
		angle -- An angle in radians
C
cjshannon 已提交
369 370
		</div>
		<div>
371
		Applies a rotation specified by an axis and an angle to this vector.
C
cjshannon 已提交
372 373
		</div>

T
tschw 已提交
374
		<h3>[method:Vector3 lerp]( [page:Vector3 v], [page:Float alpha] ) [page:Vector3 this]</h3>
C
cjshannon 已提交
375
		<div>
G
Greg Tatum 已提交
376 377
		v -- [page:Vector3] <br />
		alpha -- [page:Float] between 0 and 1.
C
cjshannon 已提交
378 379
		</div>
		<div>
380
		Linear Interpolation between this vector and vector v, where alpha is the percent along the line.
C
cjshannon 已提交
381 382
		</div>

T
tschw 已提交
383
		<h3>[method:Vector3 lerpVectors]( [page:Vector3 v1], [page:Vector3 v2], [page:Float alpha] ) [page:Vector3 this]</h3>
W
WestLangley 已提交
384 385 386 387 388 389 390 391 392
		<div>
		v1 -- [page:Vector3] <br />
		v2 -- [page:Vector3] <br />
		alpha -- [page:Float] between 0 and 1.
		</div>
		<div>
		Sets this vector to be the vector linearly interpolated between *v1* and *v2* with *alpha* factor.
		</div>

T
tschw 已提交
393
		<h3>[method:Float angleTo]( [page:Vector3 v] ) [page:Vector3 this]</h3>
C
cjshannon 已提交
394
		<div>
G
Greg Tatum 已提交
395
		v -- [page:Vector3]
C
cjshannon 已提交
396 397
		</div>
		<div>
398
		Returns the angle between this vector and vector v in radians.
C
cjshannon 已提交
399 400
		</div>

A
aardgoose 已提交
401
		<h3>[method:Vector3 setFromMatrixColumn]( [page:Matrix4 matrix], [page:Integer index] ) [page:Vector3 this]</h3>
C
cjshannon 已提交
402
		<div>
A
aardgoose 已提交
403 404
		matrix -- [page:Matrix4]<br />
		index -- 0, 1, 2, or 3
C
cjshannon 已提交
405 406
		</div>
		<div>
407
		Sets this vector's x, y, and z equal to the column of the matrix specified by the index.
C
cjshannon 已提交
408 409
		</div>

T
tschw 已提交
410
		<h3>[method:Vector3 reflect]( [page:Vector3 normal] ) [page:Vector3 this]</h3>
C
cjshannon 已提交
411
		<div>
412
		normal -- [page:Vector3] the normal to the reflecting plane
C
cjshannon 已提交
413 414
		</div>
		<div>
415
		Reflect incident vector off of plane orthogonal to normal. Normal is assumed to have unit length.
C
cjshannon 已提交
416 417
		</div>

T
tschw 已提交
418
		<h3>[method:Vector3 multiply]( [page:Vector3 v] ) [page:Vector3 this]</h3>
C
cjshannon 已提交
419
		<div>
G
Greg Tatum 已提交
420
		v -- [page:Vector3] <br />
C
cjshannon 已提交
421 422
		</div>
		<div>
423
		Multiplies this vector by vector v.
C
cjshannon 已提交
424 425
		</div>

T
tschw 已提交
426
		<h3>[method:Vector3 applyProjection]( [page:Matrix4 m] ) [page:Vector3 this]</h3>
C
cjshannon 已提交
427
		<div>
G
Greg Tatum 已提交
428
		m -- [page:Matrix4] projection matrix.
C
cjshannon 已提交
429 430
		</div>
		<div>
W
Walker Flynn 已提交
431
		Multiplies this vector and m, and divides by perspective.
C
cjshannon 已提交
432 433
		</div>

T
tschw 已提交
434
		<h3>[method:Vector3 applyEuler]( [page:Euler euler] ) [page:Vector3 this]</h3>
C
cjshannon 已提交
435
		<div>
G
Greg Tatum 已提交
436
		euler -- [page:Euler]
C
cjshannon 已提交
437 438
		</div>
		<div>
439
		Applies euler transform to this vector by converting the [page:Euler] object to a [page:Quaternion] and applying.
C
cjshannon 已提交
440 441
		</div>

T
tschw 已提交
442
		<h3>[method:Vector3 applyQuaternion]( [page:Quaternion quaternion] ) [page:Vector3 this]</h3>
C
cjshannon 已提交
443
		<div>
G
Greg Tatum 已提交
444
		quaternion -- [page:Quaternion]
C
cjshannon 已提交
445 446
		</div>
		<div>
W
Walker Flynn 已提交
447
		Applies a [page:Quaternion] transform to this vector.
C
cjshannon 已提交
448 449
		</div>

T
tschw 已提交
450
		<h3>[method:Vector3 project]( [page:Camera camera] ) [page:Vector3 this]</h3>
M
Mr.doob 已提交
451 452 453 454 455 456 457
		<div>
		[page:Camera camera] — camera to use in the projection.<br />
		</div>
		<div>
		Projects the vector with the camera.
		</div>

T
tschw 已提交
458
		<h3>[method:Vector3 unproject]( [page:Camera camera] ) [page:Vector3 this]</h3>
M
Mr.doob 已提交
459 460 461 462 463 464 465
		<div>
		[page:Camera camera] — camera to use in the projection.<br />
		</div>
		<div>
		Unprojects the vector with the camera.
		</div>

T
tschw 已提交
466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487
		<h3>[method:Boolean equals]( [page:Vector3 v] ) [page:Vector3 this]</h3>
		<div>
		Checks for strict equality of this vector and *v*.
		</div>

		<h3>[method:Vector3 clone]() [page:Vector3 this]</h3>
		<div>
		Clones this vector.
		</div>

		<h3>[method:Array toArray]( [page:Array array], [page:Integer offset] ) [page:Vector3 this]</h3>
		<div>
		array -- An optional array to store the vector to. <br />
		offset -- An optional offset into the array.
		</div>
		<div>
		Assigns this vector's x value to array[0]. <br />
		Assigns this vector's y value to array[1]. <br />
		Assigns this vector's z value to array[2]. <br />
		Returns the created array.
		</div>

488 489 490 491 492
		<h2>Source</h2>

		[link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
	</body>
</html>