Class: Vector3
Defined in: src/math/Vector3.ts:6
Vector 3D
Constructors
Constructor
new Vector3(
x?,y?,z?,w?):Vector3
Defined in: src/math/Vector3.ts:191
Creates an instance of a Vector3 object. If you do not specify a. parameter for the constructor, a Vector3 object is created with the elements (0,0,0,0).
Parameters
x?
number = 0
The first element, such as the x coordinate.
y?
number = 0
The second element, such as the y coordinate.
z?
number = 0
The third element, such as the z coordinate.
w?
number = 0
An optional element for additional data such as the angle of rotation.
Returns
Vector3
Properties
MAX
readonlystaticMAX:Vector3
Defined in: src/math/Vector3.ts:11
Vector maximum
MIN
readonlystaticMIN:Vector3
Defined in: src/math/Vector3.ts:16
Vector minimum
SAFE_MAX
readonlystaticSAFE_MAX:Vector3
Defined in: src/math/Vector3.ts:21
Vector maximum integer value
SAFE_MIN
readonlystaticSAFE_MIN:Vector3
Defined in: src/math/Vector3.ts:26
Vector minimum integer value
X_AXIS
readonlystaticX_AXIS:Vector3
Defined in: src/math/Vector3.ts:31
X axis positive axis coordinate (1, 0, 0).
neg_X_AXIS
readonlystaticneg_X_AXIS:Vector3
Defined in: src/math/Vector3.ts:36
The X-axis is negative (-1, 0, 0).
Y_AXIS
readonlystaticY_AXIS:Vector3
Defined in: src/math/Vector3.ts:41
The y axis defined as a Vector3 object with coordinates (0,1,0).
Z_AXIS
readonlystaticZ_AXIS:Vector3
Defined in: src/math/Vector3.ts:46
The z axis defined as a Vector3 object with coordinates (0,0,1).
x
x:
number=0
Defined in: src/math/Vector3.ts:148
The first element of a Vector3 object, such as the x coordinate of a point in the three-dimensional space. The default value is 0.
y
y:
number=0
Defined in: src/math/Vector3.ts:154
The second element of a Vector3 object, such as the y coordinate of a point in the three-dimensional space. The default value is 0.
z
z:
number=0
Defined in: src/math/Vector3.ts:160
The third element of a Vector3 object, such as the y coordinate of a point in the three-dimensional space. The default value is 0.
w
w:
number=1
Defined in: src/math/Vector3.ts:167
The z component of the vector, A three-dimensional position or projection that can be used as a perspective projection We can also do w in the quaternion
Accessors
ZERO
Get Signature
get
staticZERO():Vector3
Defined in: src/math/Vector3.ts:91
Returns a new vector with zero x, y, and z components
Returns
Vector3
ONE
Get Signature
get
staticONE():Vector3
Defined in: src/math/Vector3.ts:98
Returns a new vector whose x, y, and z components are all 1
Returns
Vector3
LEFT
Get Signature
get
staticLEFT():Vector3
Defined in: src/math/Vector3.ts:105
Returns a new vector pointing to the left, x is -1, y is 0, and z is 0
Returns
Vector3
RIGHT
Get Signature
get
staticRIGHT():Vector3
Defined in: src/math/Vector3.ts:112
Returns a new vector pointing in the right direction, where x is 1, y is 0, and z is 0
Returns
Vector3
UP
Get Signature
get
staticUP():Vector3
Defined in: src/math/Vector3.ts:119
Returns a new vector pointing upwards, that is, x equals 0, y equals 1, and z equals 0
Returns
Vector3
DOWN
Get Signature
get
staticDOWN():Vector3
Defined in: src/math/Vector3.ts:126
Returns a new vector pointing down, where x is 0, y is -1, and z is 0
Returns
Vector3
BACK
Get Signature
get
staticBACK():Vector3
Defined in: src/math/Vector3.ts:133
Returns a new backward vector, x equals 0, y equals 0, and z equals negative 1
Returns
Vector3
FORWARD
Get Signature
get
staticFORWARD():Vector3
Defined in: src/math/Vector3.ts:140
Returns a new forward-pointing vector, that is, x is 0, y is 0, and z is 1
Returns
Vector3
a
Get Signature
get a():
number
Defined in: src/math/Vector3.ts:233
get the w component
Returns
number
value of w
Set Signature
set a(
value):void
Defined in: src/math/Vector3.ts:201
Set w component
Parameters
value
number
Returns
void
r
Get Signature
get r():
number
Defined in: src/math/Vector3.ts:241
get the x component
Returns
number
value of x
Set Signature
set r(
value):void
Defined in: src/math/Vector3.ts:209
Set x component
Parameters
value
number
Returns
void
g
Get Signature
get g():
number
Defined in: src/math/Vector3.ts:249
get the y component
Returns
number
value of y
Set Signature
set g(
value):void
Defined in: src/math/Vector3.ts:217
Set the y component
Parameters
value
number
Returns
void
b
Get Signature
get b():
number
Defined in: src/math/Vector3.ts:257
get the z component
Returns
number
value of z
Set Signature
set b(
value):void
Defined in: src/math/Vector3.ts:225
Set z component
Parameters
value
number
Returns
void
length
Get Signature
get length():
number
Defined in: src/math/Vector3.ts:264
The length of the vector, the distance from the origin (0, 0, 0) to (x, y, z)
Returns
number
lengthSquared
Get Signature
get lengthSquared():
number
Defined in: src/math/Vector3.ts:272
You get the square of the length of the vector
Returns
number
position
Get Signature
get position():
this
Defined in: src/math/Vector3.ts:279
Get the current vector
Returns
this
Methods
getTowPointbyDir()
staticgetTowPointbyDir(dir,tp1,tp2,width,aix):void
Defined in: src/math/Vector3.ts:290
Obtain a vertical line segment with width through an orientation
Parameters
dir
Vector3
tp1
Vector3
tp2
Vector3
width
number
aix
Vector3
Returns
void
pointToLine()
staticpointToLine(point1,point2,position):number
Defined in: src/math/Vector3.ts:319
Calculate the distance from the point to the line
Parameters
point1
Vector3
Starting point of line segment
point2
Vector3
End point of line segment
position
Vector3
Point position
Returns
number
Distance from a point to a line segment
dot()
staticdot(a,b):number
Defined in: src/math/Vector3.ts:353
Take the dot product of two vectors.
Parameters
a
Vector3
Vector a
b
Vector3
Vector b
Returns
number
getPoints()
staticgetPoints(total,randSeed):any[]
Defined in: src/math/Vector3.ts:358
Generate total random Vector3 points within a cube of side randSeed centered at origin.
Parameters
total
number
randSeed
number
Returns
any[]
getPointNumbers()
staticgetPointNumbers(total,randSeed):any[]
Defined in: src/math/Vector3.ts:368
Generate total random points as a flat number array (x, y, z, ...) within a cube of side randSeed.
Parameters
total
number
randSeed
number
Returns
any[]
getAngle()
staticgetAngle(from,to):number
Defined in: src/math/Vector3.ts:382
Returns the Angle, in degrees, between the source vector and the target vector.
Parameters
from
Vector3
source vector.
to
Vector3
target vector.
Returns
number
sqrMagnitude()
staticsqrMagnitude(arg0):number
Defined in: src/math/Vector3.ts:388
Returns the squared magnitude (x^2 + y^2 + z^2) of the given vector.
Parameters
arg0
Vector3
Returns
number
getZYAngle()
staticgetZYAngle(zd,yd):number
Defined in: src/math/Vector3.ts:393
Returns the angle, in degrees, between two vectors projected onto the ZY plane.
Parameters
zd
Vector3
yd
Vector3
Returns
number
sub()
staticsub(a,b,target?):Vector3
Defined in: src/math/Vector3.ts:403
Subtract two vectors
Parameters
a
Vector3
Vector a
b
Vector3
Vector b
target?
Vector3 = null
output vector
Returns
Vector3
add()
staticadd(a,b,target?):Vector3
Defined in: src/math/Vector3.ts:419
Add two vectors
Parameters
a
Vector3
Vector a
b
Vector3
Vector b
target?
Vector3 = null
output vector
Returns
Vector3
multiply()
staticmultiply(a,b,result?):Vector3
Defined in: src/math/Vector3.ts:430
Component-wise multiply two vectors
Parameters
a
Vector3
b
Vector3
result?
Vector3
Returns
Vector3
divide()
staticdivide(a,b,result?):Vector3
Defined in: src/math/Vector3.ts:441
Component-wise divide two vectors
Parameters
a
Vector3
b
Vector3
result?
Vector3
Returns
Vector3
multiplyScalar()
staticmultiplyScalar(a,s,result?):Vector3
Defined in: src/math/Vector3.ts:452
Multiply a vector by a scalar
Parameters
a
Vector3
s
number
result?
Vector3
Returns
Vector3
addScaledVector()
staticaddScaledVector(a,b,s,result?):Vector3
Defined in: src/math/Vector3.ts:463
result = a + b * s
Parameters
a
Vector3
b
Vector3
s
number
result?
Vector3
Returns
Vector3
cross()
staticcross(a,b,result?):Vector3
Defined in: src/math/Vector3.ts:474
Cross product of two vectors
Parameters
a
Vector3
b
Vector3
result?
Vector3
Returns
Vector3
negate()
staticnegate(a,result?):Vector3
Defined in: src/math/Vector3.ts:488
Negate a vector
Parameters
a
Vector3
result?
Vector3
Returns
Vector3
min()
staticmin(a,b,result?):Vector3
Defined in: src/math/Vector3.ts:499
Component-wise minimum of two vectors
Parameters
a
Vector3
b
Vector3
result?
Vector3
Returns
Vector3
max()
staticmax(a,b,result?):Vector3
Defined in: src/math/Vector3.ts:510
Component-wise maximum of two vectors
Parameters
a
Vector3
b
Vector3
result?
Vector3
Returns
Vector3
distance()
staticdistance(pt1,pt2):number
Defined in: src/math/Vector3.ts:553
Calculate the distance between two vectors
Parameters
pt1
Vector3
Vector 1
pt2
Vector3
Vector 2
Returns
number
number The distance between two vectors
squareDistance()
staticsquareDistance(pt1,pt2):number
Defined in: src/math/Vector3.ts:566
Calculate the square distance between two vectors
Parameters
pt1
Vector3
Vector 1
pt2
Vector3
Vector 2
Returns
number
number The square distance between two vectors
distanceXZ()
staticdistanceXZ(pt1,pt2):number
Defined in: src/math/Vector3.ts:578
Calculate the distance between two vectors XZ axes
Parameters
pt1
Vector3
Vector 1
pt2
Vector3
Vector 2
Returns
number
number The distance between two vectors
set()
set(
x,y,z,w?):Vector3
Defined in: src/math/Vector3.ts:593
Sets the current vector x, y, z, and w components
Parameters
x
number
y
number
z
number
w?
number = 1
Returns
Vector3
add()
add(
a):this
Defined in: src/math/Vector3.ts:604
Adds vector a to this vector (component-wise on xyz). Mutates and returns this.
Parameters
a
Vector3
Returns
this
addVectors()
addVectors(
a,b):this
Defined in: src/math/Vector3.ts:609
Set this = a + b. Ternary mutator form.
Parameters
a
Vector3
b
Vector3
Returns
this
subVectors()
subVectors(
a,b):this
Defined in: src/math/Vector3.ts:614
Set this = a - b. Mutates and returns this.
Parameters
a
Vector3
b
Vector3
Returns
this
multiplyVectors()
multiplyVectors(
a,b):this
Defined in: src/math/Vector3.ts:619
Set this = a * b component-wise.
Parameters
a
Vector3
b
Vector3
Returns
this
addScalar()
addScalar(
scalar):Vector3
Defined in: src/math/Vector3.ts:624
Add scalar to x, y, and z. Mutates and returns this.
Parameters
scalar
number
Returns
Vector3
subScalar()
subScalar(
scalar):Vector3
Defined in: src/math/Vector3.ts:632
Subtract scalar from x, y, and z. Mutates and returns this.
Parameters
scalar
number
Returns
Vector3
min()
min(
v):this
Defined in: src/math/Vector3.ts:642
Component-wise minimum with v. Mutates and returns this.
Parameters
v
Vector3
Returns
this
max()
max(
v):this
Defined in: src/math/Vector3.ts:649
Component-wise maximum with v. Mutates and returns this.
Parameters
v
Vector3
Returns
this
distanceToSquared()
distanceToSquared(
v):number
Defined in: src/math/Vector3.ts:654
Squared Euclidean distance from this vector to v.
Parameters
v
Vector3
Returns
number
addXYZW()
addXYZW(
x,y,z,w):this
Defined in: src/math/Vector3.ts:664
Adds (x, y, z, w) to each component. Mutates and returns this.
Parameters
x
number
y
number
z
number
w
number
Returns
this
clone()
clone():
Vector3
Defined in: src/math/Vector3.ts:675
Clone a vector with the same components as the current vector
Returns
Vector3
decrementBy()
decrementBy(
a):this
Defined in: src/math/Vector3.ts:689
Subtract two vectors and assign the result to yourself
Parameters
a
Vector3
Minus vector
Returns
this
dotProduct()
dotProduct(
a):number
Defined in: src/math/Vector3.ts:702
Calculate the dot product of two vectors and return the Angle relationship between the two vectors
Parameters
a
Vector3
The vector that you need to compute
Returns
number
number Returns the Angle relationship between two vectors
equals()
equals(
toCompare,allFour?):boolean
Defined in: src/math/Vector3.ts:724
Find whether the values of two vectors are identical
Parameters
toCompare
Vector3
The vector to compare
allFour?
boolean = false
The default parameter is 1, whether to compare the w component
Returns
boolean
A value of true if the specified Vector3 object is equal to the current Vector3 object; false if it is not equal.
incrementBy()
incrementBy(
a):this
Defined in: src/math/Vector3.ts:744
The current vector plus is equal to the vector, plus just the x, y, and z components
Parameters
a
Vector3
vector
Returns
this
divide()
divide(
v):this
Defined in: src/math/Vector3.ts:755
Component-wise divides this vector by v. Mutates and returns this.
Parameters
v
Vector3
Returns
this
negate()
negate():
Vector3
Defined in: src/math/Vector3.ts:766
Sets the current Vector3 object to its inverse. The inverse object is also considered the opposite of the original object. The value of the x, y, and z properties of the current Vector3 object is changed to -x, -y, and -z.
Returns
Vector3
normalize()
normalize(
thickness?):Vector3
Defined in: src/math/Vector3.ts:781
Scales the line segment between(0,0) and the current point to a set length.
Parameters
thickness?
number = 1
The scaling value. For example, if the current Vector3 object is (0,3,4), and you normalize it to 1, the point returned is at(0,0.6,0.8).
Returns
Vector3
applyQuaternion()
applyQuaternion(
q):Vector3
Defined in: src/math/Vector3.ts:798
Apply the rotation quaternion
Parameters
q
any
quaternion
Returns
Vector3
applyMatrix4()
applyMatrix4(
m):this
Defined in: src/math/Vector3.ts:824
Transform this vector as a point by Matrix4 m. Mutates and returns this.
Parameters
m
any
Returns
this
setTo()
setTo(
xa,ya,za,wa?):void
Defined in: src/math/Vector3.ts:836
Parameters
xa
number
The first element, such as the x coordinate.
ya
number
The second element, such as the y coordinate.
za
number
The third element, such as the z coordinate.
wa?
number = 1
Returns
void
Language
en_US Sets the members of Vector3 to the specified values
copy()
copy(
src):this
Defined in: src/math/Vector3.ts:848
Copy the components of the source vector to this vector
Parameters
src
Vector3
Source vector
Returns
this
sub()
sub(
a):this
Defined in: src/math/Vector3.ts:867
Parameters
a
Vector3
The Vector3 object to be subtracted from the current Vector3 object.
Returns
this
A new Vector3 object that is the difference between the current Vector3 and the specified Vector3 object.
Language
en_US Subtracts the value of the x, y, and z elements of the current Vector3 object from the values of the x, y, and z elements of another Vector3 object. Returns a new Vector3.
multiply()
multiply(
other):this
Defined in: src/math/Vector3.ts:874
Component-wise multiplies this vector by other. Mutates and returns this.
Parameters
other
Vector3
Returns
this
lerp()
lerp(
v0,v1,t):void
Defined in: src/math/Vector3.ts:884
Computes the linear interpolation between two Vector3, and the result is the current object
Parameters
v0
Vector3
Vector 1
v1
Vector3
Vector 2
t
number
Interpolation factor
Returns
void
clamp()
clamp(
min,max):Vector3
Defined in: src/math/Vector3.ts:906
The x, y, and z components of this vector are rounded upward to the nearest integers.
Parameters
min
Vector3
minimum value
max
Vector3
maximum value
Returns
Vector3
toString()
toString():
string
Defined in: src/math/Vector3.ts:972
Returns the string form of the current vector
Returns
string
normalizeToWay2D_XY()
normalizeToWay2D_XY():
void
Defined in: src/math/Vector3.ts:989
Snap this vector to the nearest 2D axis direction (LEFT/RIGHT/UP/DOWN) based on x and y.
Returns
void
toArray()
toArray():
number[]
Defined in: src/math/Vector3.ts:1008
Returns the x, y, and z components as a new array.
Returns
number[]
copyToBytes()
copyToBytes(
byte):void
Defined in: src/math/Vector3.ts:1013
Write x, y, and z as little-endian float32 values into the DataView.
Parameters
byte
DataView
Returns
void
cross()
cross(
a):this
Defined in: src/math/Vector3.ts:1028
Cross product with another vector. Returns a new Vector3.
Parameters
a
Vector3
Returns
this
crossVectors()
crossVectors(
a,b):this
Defined in: src/math/Vector3.ts:1033
Set this = cross product of a and b. Mutates and returns this.
Parameters
a
Vector3
b
Vector3
Returns
this
multiplyScalar()
multiplyScalar(
scalar):Vector3
Defined in: src/math/Vector3.ts:1039
Multiply x, y, and z by scalar. Mutates and returns this.
Parameters
scalar
number
Returns
Vector3
setFromArray()
setFromArray(
array,firstElementPos?):void
Defined in: src/math/Vector3.ts:1048
Set x/y/z from array starting at firstElementPos.
Parameters
array
number[]
firstElementPos?
number = 0
Returns
void
divideScalar()
divideScalar(
scalar):this
Defined in: src/math/Vector3.ts:1057
Divides this vector by scalar. Mutates and returns this.
Parameters
scalar
number
Returns
this
clampLength()
clampLength(
min,max):this
Defined in: src/math/Vector3.ts:1064
Clamps the length of this vector into [min, max]. Mutates and returns this.
Parameters
min
number
max
number
Returns
this
setScalar()
setScalar(
value):Vector3
Defined in: src/math/Vector3.ts:1070
Set x, y, and z all to value. Mutates and returns this.
Parameters
value
number
Returns
Vector3
addScaledVector()
addScaledVector(
v,scale):Vector3
Defined in: src/math/Vector3.ts:1078
Add v * scale to this vector. Mutates and returns this.
Parameters
v
Vector3
scale
number
Returns
Vector3
dot()
dot(
v):number
Defined in: src/math/Vector3.ts:1088
Dot product. Canonical alias of dotProduct.
Parameters
v
Vector3
Returns
number
lengthSq()
lengthSq():
number
Defined in: src/math/Vector3.ts:1093
Squared length of this vector.
Returns
number
distanceTo()
distanceTo(
v):number
Defined in: src/math/Vector3.ts:1098
Euclidean distance to v.
Parameters
v
Vector3
Returns
number
angleTo()
angleTo(
v):number
Defined in: src/math/Vector3.ts:1103
Angle between this and v, in radians (range [0, π]).
Parameters
v
Vector3
Returns
number
lerpVectors()
lerpVectors(
v1,v2,alpha):this
Defined in: src/math/Vector3.ts:1111
Set this to v1 + (v2 - v1) * alpha. Canonical alias of lerp.
Parameters
v1
Vector3
v2
Vector3
alpha
number
Returns
this
setFromMatrixPosition()
setFromMatrixPosition(
m):this
Defined in: src/math/Vector3.ts:1117
Set this = position column of Matrix4 m.
Parameters
m
rawData
ArrayLike<number>
Returns
this
setFromMatrixScale()
setFromMatrixScale(
m):this
Defined in: src/math/Vector3.ts:1126
Set this = scale extracted from Matrix4 m (length of each column basis).
Parameters
m
rawData
ArrayLike<number>
Returns
this
setFromMatrixColumn()
setFromMatrixColumn(
m,index):this
Defined in: src/math/Vector3.ts:1138
Set this = column index of Matrix4 m (0, 1, 2, or 3).
Parameters
m
rawData
ArrayLike<number>
index
number
Returns
this
projectOnVector()
projectOnVector(
v):this
Defined in: src/math/Vector3.ts:1148
Project this onto v. Mutates and returns this.
Parameters
v
Vector3
Returns
this
projectOnPlane()
projectOnPlane(
planeNormal):this
Defined in: src/math/Vector3.ts:1156
Project this onto a plane defined by its normal (unit vector).
Parameters
planeNormal
Vector3
Returns
this
reflect()
reflect(
normal):this
Defined in: src/math/Vector3.ts:1162
Reflect this off a surface with the given unit normal.
Parameters
normal
Vector3
Returns
this
applyMatrix3()
applyMatrix3(
m):this
Defined in: src/math/Vector3.ts:1167
Apply a 3x3 matrix to this vector.
Parameters
m
{ rawData: ArrayLike<number>; } | { a: number; b: number; c: number; d: number; tx: number; ty: number; }
Returns
this
applyAxisAngle()
applyAxisAngle(
axis,angle):this
Defined in: src/math/Vector3.ts:1185
Apply axis-angle rotation (axis must be unit, angle in radians).
Parameters
axis
Vector3
angle
number
Returns
this
transformDirection()
transformDirection(
m):this
Defined in: src/math/Vector3.ts:1195
Transform this as a direction (no translation) by Matrix4 m, then normalize.
Parameters
m
rawData
ArrayLike<number>
Returns
this
fromArray()
fromArray(
array,offset?):this
Defined in: src/math/Vector3.ts:1205
Canonical alias of setFromArray.
Parameters
array
ArrayLike<number>
offset?
number = 0
Returns
this
floor()
floor():
this
Defined in: src/math/Vector3.ts:1213
Floors each component. Mutates and returns this.
Returns
this
ceil()
ceil():
this
Defined in: src/math/Vector3.ts:1221
Ceils each component. Mutates and returns this.
Returns
this
round()
round():
this
Defined in: src/math/Vector3.ts:1229
Rounds each component to the nearest integer. Mutates and returns this.
Returns
this
roundToZero()
roundToZero():
this
Defined in: src/math/Vector3.ts:1237
Rounds each component toward zero. Mutates and returns this.
Returns
this
random()
random():
this
Defined in: src/math/Vector3.ts:1245
Fill this with components in [0, 1).
Returns
this
pointInsideTriangle()
staticpointInsideTriangle(pt,pt0,pt1,pt2):boolean
Defined in: src/math/Vector3.ts:1277
Tests whether point pt lies inside the triangle (pt0, pt1, pt2), using their x/z coordinates.
Parameters
pt
Vector3
pt0
Vector3
pt1
Vector3
pt2
Vector3
Returns
boolean
serialize()
staticserialize(position):Vector3
Defined in: src/math/Vector3.ts:1307
Returns a new Vector3 copy of the given vector, used for serialization.
Parameters
position
Vector3
Returns
Vector3

