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

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


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

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

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


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

C
cjshannon 已提交
27

28
		<h3>[name]( [page:Float x], [page:Float y], [page:Float z] )</h3>
C
cjshannon 已提交
29
		<div>
30 31 32
		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 已提交
33 34
		</div>
		<div>
35
		A 3 dimensional vector
C
cjshannon 已提交
36
		</div>
M
Mr.doob 已提交
37 38


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

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

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

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


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

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

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

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

G
Greg Tatum 已提交
65
		<h3>.setZ( [page:Float z] ) [page:Vector3 this]</h3>
66 67 68 69
		<div>
		Sets z value of this vector.
		</div>

G
Greg Tatum 已提交
70
		<h3>.copy( [page:Vector3 v] ) [page:Vector3 this]</h3>
71 72 73 74
		<div>
		Copies value of *v* to this vector.
		</div>

G
Greg Tatum 已提交
75
		<h3>.add( [page:Vector3 v] ) [page:Vector3 this]</h3>
76
		<div>
77
		Adds *v* to this vector.
78 79
		</div>

G
Greg Tatum 已提交
80
		<h3>.addVectors( [page:Vector3 a], [page:Vector3 b] ) [page:Vector3 this]</h3>
81
		<div>
82
		Sets this vector to *a + b*.
83 84
		</div>

G
Greg Tatum 已提交
85
		<h3>.sub( [page:Vector3 v] ) [page:Vector3 this]</h3>
86
		<div>
87
		Subtracts *v* from this vector.
88 89
		</div>

G
Greg Tatum 已提交
90
		<h3>.subVectors( [page:Vector3 a], [page:Vector3 b] ) [page:Vector3 this]</h3>
91
		<div>
92
		Sets this vector to *a - b*.
93 94
		</div>

G
Greg Tatum 已提交
95
		<h3>.multiplyScalar( [page:Float s] ) [page:Vector3 this]</h3>
96 97 98
		<div>
		Multiplies this vector by scalar *s*.
		</div>
M
Mr.doob 已提交
99

G
Greg Tatum 已提交
100
		<h3>.divideScalar( [page:Float s] ) [page:Vector3 this]</h3>
101 102 103 104 105
		<div>
		Divides this vector by scalar *s*.<br />
		Set vector to *( 0, 0, 0 )* if *s == 0*.
		</div>

G
Greg Tatum 已提交
106
		<h3>.negate() [page:Vector3 this]</h3>
107 108 109 110 111 112 113 114
		<div>
		Inverts this vector.
		</div>

		<h3>.dot( [page:Vector3 v] ) [page:Float]</h3>
		<div>
		Computes dot product of this vector and *v*.
		</div>
M
Mr.doob 已提交
115

116 117 118 119
		<h3>.lengthSq() [page:Float]</h3>
		<div>
		Computes squared length of this vector.
		</div>
M
Mr.doob 已提交
120

121 122 123 124
		<h3>.length() [page:Float]</h3>
		<div>
		Computes length of this vector.
		</div>
M
Mr.doob 已提交
125

126 127 128 129 130 131
		<h3>.lengthManhattan() [page:Float]</h3>
		<div>
		Computes Manhattan length of this vector.<br />
		[link:http://en.wikipedia.org/wiki/Taxicab_geometry]
		</div>

G
Greg Tatum 已提交
132
		<h3>.normalize() [page:Vector3 this]</h3>
133
		<div>
134
		Normalizes this vector. Transforms this Vector into a Unit vector by dividing the vector by it's length.
135 136
		</div>

M
Mr.doob 已提交
137
		<h3>.distanceTo( [page:Vector3 v] ) [page:Float]</h3>
138 139 140 141
		<div>
		Computes distance of this vector to *v*.
		</div>

M
Mr.doob 已提交
142
		<h3>.distanceToSquared( [page:Vector3 v] ) [page:Float]</h3>
143 144 145 146
		<div>
		Computes squared distance of this vector to *v*.
		</div>

G
Greg Tatum 已提交
147
		<h3>.setLength( [page:Float l] ) [page:Vector3 this]</h3>
148 149 150 151
		<div>
		Normalizes this vector and multiplies it by *l*.
		</div>

G
Greg Tatum 已提交
152
		<h3>.cross( [page:Vector3 v] ) [page:Vector3 this]</h3>
153
		<div>
154
		Sets this vector to cross product of itself and *v*.
155 156
		</div>

G
Greg Tatum 已提交
157
		<h3>.crossVectors( [page:Vector3 a], [page:Vector3 b] ) [page:Vector3 this]</h3>
158
		<div>
159
		Sets this vector to cross product of *a* and *b*.
160 161
		</div>

162
		<h3>.setFromMatrixPosition( [page:Matrix4 m] ) [page:Vector3 this]</h3>
163 164 165 166
		<div>
		Sets this vector extracting position from matrix transform.
		</div>

167
		<h3>.setFromMatrixScale( [page:Matrix4 m] ) [page:Vector3 this]</h3>
168 169 170 171
		<div>
		Sets this vector extracting scale from matrix transform.
		</div>

172
		<h3>.equals( [page:Vector3 v] ) [page:Boolean]</h3>
173 174 175 176 177 178 179 180 181 182
		<div>
		Checks for strict equality of this vector and *v*.
		</div>

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


G
Greg Tatum 已提交
183
		<h3>.clamp([page:Vector3 min], [page:Vector3 max]) [page:Vector3 this]</h3>
C
cjshannon 已提交
184
		<div>
185 186
		min -- [page:Vector3] <br />
		max -- [page:Vector3]
C
cjshannon 已提交
187 188
		</div>
		<div>
G
Greg Tatum 已提交
189 190
		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 />
		If this vector's x, y or z value is less than the min vector's x, y or z value, it is replace by the corresponding value.
C
cjshannon 已提交
191 192
		</div>

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
		<h3>.clampScalar([page:Float min], [page:Float max]) [page:Vector3 this]</h3>
		<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>
		If this vector's x, y or z values are greater than the max value, they are replaced by the max value. <br />  If this vector's x, y or z values are less than the min value, they are replace by the min value.
		</div>

		<h3>.floor() [page:Vector3]</h3>
		<div>
		The components of the vector are rounded downwards (towards negative infinity) to an integer value.
		</div>

		<h3>.ceil() [page:Vector3]</h3>
		<div>
		The components of the vector are rounded upwards (towards positive infinity) to an integer value.
		</div>

		<h3>.round() [page:Vector3]</h3>
		<div>
		The components of the vector are rounded towards the nearest integer value.
		</div>

		<h3>.roundToZero() [page:Vector3]</h3>
		<div>
		The components of the vector are rounded towards zero (up if negative, down if positive) to an integer value.
		</div>

G
Greg Tatum 已提交
222
		<h3>.applyMatrix3([page:Matrix3 m]) [page:Vector3 this]</h3>
C
cjshannon 已提交
223
		<div>
224
		m -- [page:Matrix3]
C
cjshannon 已提交
225 226
		</div>
		<div>
227
		Multiplies this vector times a 3 x 3 matrix.
C
cjshannon 已提交
228 229
		</div>

G
Greg Tatum 已提交
230
		<h3>.applyMatrix4([page:Matrix3 m]) [page:Vector3 this]</h3>
C
cjshannon 已提交
231
		<div>
G
Greg Tatum 已提交
232
		m -- [page:Matrix4]
C
cjshannon 已提交
233 234
		</div>
		<div>
235
		Multiplies this vector by 4 x 3 subset of a Matrix4.
C
cjshannon 已提交
236 237
		</div>

G
Greg Tatum 已提交
238
		<h3>.projectOnPlane([page:Vector3 planeNormal]) [page:Vector3 this]</h3>
C
cjshannon 已提交
239
		<div>
G
Greg Tatum 已提交
240
		planeNormal -- [page:Vector3 planeNormal] A vector representing a plane normal.
C
cjshannon 已提交
241 242
		</div>
		<div>
243
		Projects this vector onto a plane by subtracting this vector projected onto the plane's normal from this vector.
C
cjshannon 已提交
244 245
		</div>

G
Greg Tatum 已提交
246
		<h3>.projectOnVector([page:Vector3]) [page:Vector3 this]</h3>
C
cjshannon 已提交
247
		<div>
G
Greg Tatum 已提交
248
		vector -- [page:Vector3]
C
cjshannon 已提交
249 250
		</div>
		<div>
251
		Projects this vector onto another vector.
C
cjshannon 已提交
252 253
		</div>

G
Greg Tatum 已提交
254
		<h3>.addScalar([page:Float]) [page:Vector3 this]</h3>
C
cjshannon 已提交
255
		<div>
G
Greg Tatum 已提交
256
		s -- [page:Float]
C
cjshannon 已提交
257 258
		</div>
		<div>
259
		Adds a s to this vector.
C
cjshannon 已提交
260 261
		</div>

G
Greg Tatum 已提交
262
		<h3>.divide([page:Vector3 v]) [page:Vector3 this]</h3>
C
cjshannon 已提交
263
		<div>
G
Greg Tatum 已提交
264
		v -- [page:Vector3]
C
cjshannon 已提交
265 266
		</div>
		<div>
267
		Divides this vector by vector v.
C
cjshannon 已提交
268 269
		</div>

G
Greg Tatum 已提交
270
		<h3>.min([page:Vector3 v]) [page:Vector3 this]</h3>
C
cjshannon 已提交
271
		<div>
G
Greg Tatum 已提交
272
		v -- [page:Vector3]
C
cjshannon 已提交
273 274
		</div>
		<div>
275
		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.
C
cjshannon 已提交
276 277
		</div>

G
Greg Tatum 已提交
278 279 280 281 282 283 284 285 286
		<h3>.max([page:Vector3 v]) [page:Vector3 this]</h3>
		<div>
		v -- [page:Vector3]
		</div>
		<div>
		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.
		</div>

		<h3>.setComponent([page:Integer index], [page:Float value]) [page:Vector3 this]</h3>
C
cjshannon 已提交
287
		<div>
288
		index -- 0, 1, or 2 <br />
G
Greg Tatum 已提交
289
		value -- [page:Float]
C
cjshannon 已提交
290 291
		</div>
		<div>
292 293 294
		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 已提交
295 296
		</div>

G
Greg Tatum 已提交
297
		<h3>.transformDirection([page:Matrix4 m]) [page:Vector3 this]</h3>
C
cjshannon 已提交
298
		<div>
G
Greg Tatum 已提交
299
		m -- [page:Matrix4]
C
cjshannon 已提交
300 301
		</div>
		<div>
G
Greg Tatum 已提交
302
		Transforms the direction of this vector by a matrix (a 3 x 3 subset of a Matrix4) and then normalizes the result.
C
cjshannon 已提交
303 304
		</div>

G
Greg Tatum 已提交
305
		<h3>.multiplyVectors([page:Vector3 a], [page:Vector3 b]) [page:Vector3 this]</h3>
C
cjshannon 已提交
306
		<div>
G
Greg Tatum 已提交
307 308
		a -- [page:Vector3] <br />
		b -- [page:Vector3]
C
cjshannon 已提交
309 310
		</div>
		<div>
G
Greg Tatum 已提交
311
		Sets this vector equal to the result of multiplying vector a by vector b.
C
cjshannon 已提交
312 313
		</div>

G
Greg Tatum 已提交
314
		<h3>.getComponent([page:Integer index]) [page:Float]</h3>
C
cjshannon 已提交
315
		<div>
G
Greg Tatum 已提交
316
		index -- [page:Integer] 0, 1, or 2
C
cjshannon 已提交
317 318
		</div>
		<div>
M
Mr.doob 已提交
319

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

G
Greg Tatum 已提交
322 323 324
		Index 0: x <br />
		Index 1: y <br />
		Index 2: z <br />
C
cjshannon 已提交
325 326
		</div>

G
Greg Tatum 已提交
327
		<h3>.applyAxisAngle([page:Vector3 axis], [page:Float angle]) [page:Vector3 this]</h3>
C
cjshannon 已提交
328
		<div>
G
Greg Tatum 已提交
329 330
		axis -- A normalized [page:Vector3] <br />
		angle -- An angle in radians
C
cjshannon 已提交
331 332
		</div>
		<div>
333
		Applies a rotation specified by an axis and an angle to this vector.
C
cjshannon 已提交
334 335
		</div>

G
Greg Tatum 已提交
336
		<h3>.lerp([page:Vector3 v], [page:Float alpha]) [page:Vector3 this]</h3>
C
cjshannon 已提交
337
		<div>
G
Greg Tatum 已提交
338 339
		v -- [page:Vector3] <br />
		alpha -- [page:Float] between 0 and 1.
C
cjshannon 已提交
340 341
		</div>
		<div>
342
		Linear Interpolation between this vector and vector v, where alpha is the percent along the line.
C
cjshannon 已提交
343 344
		</div>

G
Greg Tatum 已提交
345
		<h3>.angleTo([page:Vector3 v]) [page:Float]</h3>
C
cjshannon 已提交
346
		<div>
G
Greg Tatum 已提交
347
		v -- [page:Vector3]
C
cjshannon 已提交
348 349
		</div>
		<div>
350
		Returns the angle between this vector and vector v in radians.
C
cjshannon 已提交
351 352
		</div>

353
		<h3>.setFromMatrixColumn([page:Integer index], [page:Matrix4 matrix]) [page:Vector3 this]</h3>
C
cjshannon 已提交
354
		<div>
355
		index -- 0, 1, 2, or 3 <br />
G
Greg Tatum 已提交
356
		matrix -- [page:Matrix4]
C
cjshannon 已提交
357 358
		</div>
		<div>
359
		Sets this vector's x, y, and z equal to the column of the matrix specified by the index.
C
cjshannon 已提交
360 361
		</div>

362
		<h3>.reflect([page:Vector3 normal]) [page:Vector3 this]</h3>
C
cjshannon 已提交
363
		<div>
364
		normal -- [page:Vector3] the normal to the reflecting plane
C
cjshannon 已提交
365 366
		</div>
		<div>
367
		Reflect incident vector off of plane orthogonal to normal. normal is assumed to have unit length.
C
cjshannon 已提交
368 369
		</div>

G
Greg Tatum 已提交
370
		<h3>.fromArray([page:Array array]) [page:Vector3 this]</h3>
C
cjshannon 已提交
371
		<div>
G
Greg Tatum 已提交
372
		array -- [page:Array] [x, y, z]
C
cjshannon 已提交
373 374
		</div>
		<div>
G
Greg Tatum 已提交
375
		Sets the vector's components based on an array formatted like [x, y, z]
C
cjshannon 已提交
376 377
		</div>

G
Greg Tatum 已提交
378
		<h3>.multiply([page:Vector3 v]) [page:Vector3 this]</h3>
C
cjshannon 已提交
379
		<div>
G
Greg Tatum 已提交
380
		v -- [page:Vector3] <br />
C
cjshannon 已提交
381 382
		</div>
		<div>
W
Walker Flynn 已提交
383
		Multipies this vector by vector v.
C
cjshannon 已提交
384 385
		</div>

G
Greg Tatum 已提交
386
		<h3>.applyProjection([page:Matrix4 m]) [page:Vector3 this]</h3>
C
cjshannon 已提交
387
		<div>
G
Greg Tatum 已提交
388
		m -- [page:Matrix4] projection matrix.
C
cjshannon 已提交
389 390
		</div>
		<div>
W
Walker Flynn 已提交
391
		Multiplies this vector and m, and divides by perspective.
C
cjshannon 已提交
392 393
		</div>

G
Greg Tatum 已提交
394
		<h3>.toArray() [page:Array]</h3>
C
cjshannon 已提交
395
		<div>
396 397 398 399
		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.
C
cjshannon 已提交
400 401
		</div>

G
Greg Tatum 已提交
402
		<h3>.applyEuler([page:Euler euler]) [page:Vector3 this]</h3>
C
cjshannon 已提交
403
		<div>
G
Greg Tatum 已提交
404
		euler -- [page:Euler]
C
cjshannon 已提交
405 406
		</div>
		<div>
W
Walker Flynn 已提交
407
		Applies euler transform to this vector by converting the [page:Euler] obect to a [page:Quaternion] and applying.
C
cjshannon 已提交
408 409
		</div>

G
Greg Tatum 已提交
410
		<h3>.applyQuaternion([page:Quaternion quaternion]) [page:Vector3 this]</h3>
C
cjshannon 已提交
411
		<div>
G
Greg Tatum 已提交
412
		quaternion -- [page:Quaternion]
C
cjshannon 已提交
413 414
		</div>
		<div>
W
Walker Flynn 已提交
415
		Applies a [page:Quaternion] transform to this vector.
C
cjshannon 已提交
416 417
		</div>

M
Mr.doob 已提交
418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433
		<h3>.projectCamera( [page:Camera camera] ) [page:Vector3]</h3>
		<div>
		[page:Camera camera] — camera to use in the projection.<br />
		</div>
		<div>
		Projects the vector with the camera.
		</div>

		<h3>.unprojectCamera( [page:Camera camera] ) [page:Vector3]</h3>
		<div>
		[page:Camera camera] — camera to use in the projection.<br />
		</div>
		<div>
		Unprojects the vector with the camera.
		</div>

434 435 436 437 438
		<h2>Source</h2>

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