Skip to content

Class: Vector3

Vector 3D

Hierarchy

Constructors

Properties

Accessors

Methods

Constructors

constructor

new Vector3(x?, y?, z?, w?): Vector3

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

NameTypeDefault valueDescription
xnumber0The first element, such as the x coordinate.
ynumber0The second element, such as the y coordinate.
znumber0The third element, such as the z coordinate.
wnumber0An optional element for additional data such as the angle of rotation.

Returns

Vector3

Defined in

src/math/Vector3.ts:191

Properties

MAX

Static Readonly MAX: Vector3

Vector maximum

Defined in

src/math/Vector3.ts:11


MIN

Static Readonly MIN: Vector3

Vector minimum

Defined in

src/math/Vector3.ts:16


SAFE_MAX

Static Readonly SAFE_MAX: Vector3

Vector maximum integer value

Defined in

src/math/Vector3.ts:21


SAFE_MIN

Static Readonly SAFE_MIN: Vector3

Vector minimum integer value

Defined in

src/math/Vector3.ts:26


X_AXIS

Static Readonly X_AXIS: Vector3

X axis positive axis coordinate (1, 0, 0).

Defined in

src/math/Vector3.ts:31


neg_X_AXIS

Static Readonly neg_X_AXIS: Vector3

The X-axis is negative (-1, 0, 0).

Defined in

src/math/Vector3.ts:36


Y_AXIS

Static Readonly Y_AXIS: Vector3

The y axis defined as a Vector3 object with coordinates (0,1,0).

Defined in

src/math/Vector3.ts:41


Z_AXIS

Static Readonly Z_AXIS: Vector3

The z axis defined as a Vector3 object with coordinates (0,0,1).

Defined in

src/math/Vector3.ts:46


x

x: number = 0

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.

Defined in

src/math/Vector3.ts:148


y

y: number = 0

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.

Defined in

src/math/Vector3.ts:154


z

z: number = 0

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.

Defined in

src/math/Vector3.ts:160


w

w: number = 1

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

Defined in

src/math/Vector3.ts:167

Accessors

ZERO

get ZERO(): Vector3

Returns a new vector with zero x, y, and z components

Returns

Vector3

Defined in

src/math/Vector3.ts:91


ONE

get ONE(): Vector3

Returns a new vector whose x, y, and z components are all 1

Returns

Vector3

Defined in

src/math/Vector3.ts:98


LEFT

get LEFT(): Vector3

Returns a new vector pointing to the left, x is -1, y is 0, and z is 0

Returns

Vector3

Defined in

src/math/Vector3.ts:105


get RIGHT(): Vector3

Returns a new vector pointing in the right direction, where x is 1, y is 0, and z is 0

Returns

Vector3

Defined in

src/math/Vector3.ts:112


UP

get UP(): Vector3

Returns a new vector pointing upwards, that is, x equals 0, y equals 1, and z equals 0

Returns

Vector3

Defined in

src/math/Vector3.ts:119


DOWN

get DOWN(): Vector3

Returns a new vector pointing down, where x is 0, y is -1, and z is 0

Returns

Vector3

Defined in

src/math/Vector3.ts:126


BACK

get BACK(): Vector3

Returns a new backward vector, x equals 0, y equals 0, and z equals negative 1

Returns

Vector3

Defined in

src/math/Vector3.ts:133


FORWARD

get FORWARD(): Vector3

Returns a new forward-pointing vector, that is, x is 0, y is 0, and z is 1

Returns

Vector3

Defined in

src/math/Vector3.ts:140


a

get a(): number

get the w component

Returns

number

value of w

Defined in

src/math/Vector3.ts:233

set a(value): void

Set w component

Parameters

NameType
valuenumber

Returns

void

Defined in

src/math/Vector3.ts:201


r

get r(): number

get the x component

Returns

number

value of x

Defined in

src/math/Vector3.ts:241

set r(value): void

Set x component

Parameters

NameType
valuenumber

Returns

void

Defined in

src/math/Vector3.ts:209


g

get g(): number

get the y component

Returns

number

value of y

Defined in

src/math/Vector3.ts:249

set g(value): void

Set the y component

Parameters

NameType
valuenumber

Returns

void

Defined in

src/math/Vector3.ts:217


b

get b(): number

get the z component

Returns

number

value of z

Defined in

src/math/Vector3.ts:257

set b(value): void

Set z component

Parameters

NameType
valuenumber

Returns

void

Defined in

src/math/Vector3.ts:225


length

get length(): number

The length of the vector, the distance from the origin (0, 0, 0) to (x, y, z)

Returns

number

Defined in

src/math/Vector3.ts:264


lengthSquared

get lengthSquared(): number

You get the square of the length of the vector

Returns

number

Defined in

src/math/Vector3.ts:272


position

get position(): this

Get the current vector

Returns

this

Defined in

src/math/Vector3.ts:279

Methods

getTowPointbyDir

getTowPointbyDir(dir, tp1, tp2, width, aix): void

Obtain a vertical line segment with width through an orientation

Parameters

NameType
dirVector3
tp1Vector3
tp2Vector3
widthnumber
aixVector3

Returns

void

Defined in

src/math/Vector3.ts:290


pointToLine

pointToLine(point1, point2, position): number

Calculate the distance from the point to the line

Parameters

NameTypeDescription
point1Vector3Starting point of line segment
point2Vector3End point of line segment
positionVector3Point position

Returns

number

Distance from a point to a line segment

Defined in

src/math/Vector3.ts:319


dot

dot(a, b): number

Take the dot product of two vectors.

Parameters

NameTypeDescription
aVector3Vector a
bVector3Vector b

Returns

number

Defined in

src/math/Vector3.ts:353


getPoints

getPoints(total, randSeed): any[]

Parameters

NameType
totalnumber
randSeednumber

Returns

any[]

Defined in

src/math/Vector3.ts:357


getPointNumbers

getPointNumbers(total, randSeed): any[]

Parameters

NameType
totalnumber
randSeednumber

Returns

any[]

Defined in

src/math/Vector3.ts:366


getAngle

getAngle(from, to): number

Returns the Angle, in degrees, between the source vector and the target vector.

Parameters

NameTypeDescription
fromVector3source vector.
toVector3target vector.

Returns

number

Defined in

src/math/Vector3.ts:380


sqrMagnitude

sqrMagnitude(arg0): number

Parameters

NameType
arg0Vector3

Returns

number

Defined in

src/math/Vector3.ts:385


getZYAngle

getZYAngle(zd, yd): number

Parameters

NameType
zdVector3
ydVector3

Returns

number

Defined in

src/math/Vector3.ts:389


sub

sub(a, b, target?): Vector3

Subtract two vectors

Parameters

NameTypeDefault valueDescription
aVector3undefinedVector a
bVector3undefinedVector b
targetVector3nulloutput vector

Returns

Vector3

Defined in

src/math/Vector3.ts:399


add

add(a, b, target?): Vector3

Add two vectors

Parameters

NameTypeDefault valueDescription
aVector3undefinedVector a
bVector3undefinedVector b
targetVector3nulloutput vector

Returns

Vector3

Defined in

src/math/Vector3.ts:415


distance

distance(pt1, pt2): number

Calculate the distance between two vectors

Parameters

NameTypeDescription
pt1Vector3Vector 1
pt2Vector3Vector 2

Returns

number

number The distance between two vectors

Defined in

src/math/Vector3.ts:458


squareDistance

squareDistance(pt1, pt2): number

Calculate the square distance between two vectors

Parameters

NameTypeDescription
pt1Vector3Vector 1
pt2Vector3Vector 2

Returns

number

number The square distance between two vectors

Defined in

src/math/Vector3.ts:471


distanceXZ

distanceXZ(pt1, pt2): number

Calculate the distance between two vectors XZ axes

Parameters

NameTypeDescription
pt1Vector3Vector 1
pt2Vector3Vector 2

Returns

number

number The distance between two vectors

Defined in

src/math/Vector3.ts:483


set

set(x, y, z, w?): Vector3

Sets the current vector x, y, z, and w components

Parameters

NameTypeDefault value
xnumberundefined
ynumberundefined
znumberundefined
wnumber1

Returns

Vector3

Defined in

src/math/Vector3.ts:498


add

add(a, target?): Vector3

The vector is added to the vector

Parameters

NameTypeDefault valueDescription
aVector3undefinedAdditive vector
targetVector3nullReturn vector

Returns

Vector3

result

Defined in

src/math/Vector3.ts:512


subVectors

subVectors(a, b): this

Parameters

NameType
aVector3
bVector3

Returns

this

Defined in

src/math/Vector3.ts:527


distanceToSquared

distanceToSquared(v): number

Parameters

NameType
vVector3

Returns

number

Defined in

src/math/Vector3.ts:534


addXYZW

addXYZW(x, y, z, w, target?): Vector3

Parameters

NameTypeDefault value
xnumberundefined
ynumberundefined
znumberundefined
wnumberundefined
targetVector3null

Returns

Vector3

Defined in

src/math/Vector3.ts:541


clone

clone(): Vector3

Clone a vector with the same components as the current vector

Returns

Vector3

Defined in

src/math/Vector3.ts:559


copyFrom

copyFrom(src): Vector3

The components of the source vector are set to the current vector

Parameters

NameTypeDescription
srcVector3Original vector

Returns

Vector3

Defined in

src/math/Vector3.ts:568


decrementBy

decrementBy(a): void

Subtract two vectors and assign the result to yourself

Parameters

NameTypeDescription
aVector3Minus vector

Returns

void

Defined in

src/math/Vector3.ts:581


dotProduct

dotProduct(a): number

Calculate the dot product of two vectors and return the Angle relationship between the two vectors

Parameters

NameTypeDescription
aVector3The vector that you need to compute

Returns

number

number Returns the Angle relationship between two vectors

Defined in

src/math/Vector3.ts:593


equals

equals(toCompare, allFour?): boolean

Find whether the values of two vectors are identical

Parameters

NameTypeDefault valueDescription
toCompareVector3undefinedThe vector to compare
allFourbooleanfalseThe 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.

Defined in

src/math/Vector3.ts:615


incrementBy

incrementBy(a): void

The current vector plus is equal to the vector, plus just the x, y, and z components

Parameters

NameTypeDescription
aVector3vector

Returns

void

Defined in

src/math/Vector3.ts:635


divide

divide(v): Vector3

The current vector divided by the vector or component

Parameters

NameTypeDescription
vanyThe vector or component that you want to divide

Returns

Vector3

Vector3 Returns the result of the calculation

Defined in

src/math/Vector3.ts:647


negate

negate(): Vector3

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

Defined in

src/math/Vector3.ts:664


normalize

normalize(thickness?): Vector3

Scales the line segment between(0,0) and the current point to a set length.

Parameters

NameTypeDefault valueDescription
thicknessnumber1The 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

Defined in

src/math/Vector3.ts:679


applyQuaternion

applyQuaternion(q): Vector3

Apply the rotation quaternion

Parameters

NameTypeDescription
qanyquaternion

Returns

Vector3

Defined in

src/math/Vector3.ts:696


scaleBy

scaleBy(s): Vector3

Scales the current Vector3 object by a scalar, a magnitude. The Vector3 object's x, y, and z elements are multiplied by the scalar number specified in the parameter. For example, if the vector is scaled by ten, the result is a vector that is ten times longer. The scalar can also change the direction of the vector. Multiplying the vector by a negative number reverses its direction.

Parameters

NameTypeDescription
snumberA multiplier (scalar) used to scale a Vector3 object.

Returns

Vector3

Defined in

src/math/Vector3.ts:731


mul

mul(s): Vector3

The current vector times the scalar s

Parameters

NameTypeDescription
snumberscalar s

Returns

Vector3

Defined in

src/math/Vector3.ts:743


scale

scale(s): Vector3

Parameters

NameType
sVector3

Returns

Vector3

Defined in

src/math/Vector3.ts:751


scaleToRef

scaleToRef(s, ref): Vector3

Parameters

NameType
snumber
refVector3

Returns

Vector3

Defined in

src/math/Vector3.ts:758


setTo

setTo(xa, ya, za, wa?): void

Parameters

NameTypeDefault valueDescription
xanumberundefinedThe first element, such as the x coordinate.
yanumberundefinedThe second element, such as the y coordinate.
zanumberundefinedThe third element, such as the z coordinate.
wanumber1-

Returns

void

Language

en_US Sets the members of Vector3 to the specified values

Defined in

src/math/Vector3.ts:777


copy

copy(src): this

Copy the components of the source vector to this vector

Parameters

NameTypeDescription
srcVector3Source vector

Returns

this

Defined in

src/math/Vector3.ts:789


subtract

subtract(a, target?): Vector3

Parameters

NameTypeDefault valueDescription
aVector3undefinedThe Vector3 object to be subtracted from the current Vector3 object.
targetVector3null-

Returns

Vector3

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. The subtract() method does not change the current Vector3 object. Instead, this method returns a new Vector3 object with the new values.

Defined in

src/math/Vector3.ts:810


multiply

multiply(other, target?): Vector3

Let's multiply that vector times that vector.

Parameters

NameTypeDefault valueDescription
otherVector3undefinedMultiplied vectors
targetVector3nullReturned vector

Returns

Vector3

Defined in

src/math/Vector3.ts:824


divided

divided(other, target?): Vector3

Let's divide this vector by this vector.

Parameters

NameTypeDefault valueDescription
otherVector3undefinedThe vector that divides
targetVector3nullReturned vector

Returns

Vector3

Defined in

src/math/Vector3.ts:847


div

div(v, target?): Vector3

Divide that vector by the scalar

Parameters

NameTypeDescription
vnumberThe scalar that divides
target?Vector3Output a Vector3 vector

Returns

Vector3

Defined in

src/math/Vector3.ts:870


lerp

lerp(v0, v1, t): void

Computes the linear interpolation between two Vector3, and the result is the current object

Parameters

NameTypeDescription
v0Vector3Vector 1
v1Vector3Vector 2
tnumberInterpolation factor

Returns

void

Defined in

src/math/Vector3.ts:890


clamp

clamp(min, max): Vector3

The x, y, and z components of this vector are rounded upward to the nearest integers.

Parameters

NameTypeDescription
minVector3minimum value
maxVector3maximum value

Returns

Vector3

Defined in

src/math/Vector3.ts:912


toString

toString(): string

Returns the string form of the current vector

Returns

string

Defined in

src/math/Vector3.ts:978


normalizeToWay2D_XY

normalizeToWay2D_XY(): void

Returns

void

Defined in

src/math/Vector3.ts:994


toArray

toArray(): number[]

Returns

number[]

Defined in

src/math/Vector3.ts:1012


copyToBytes

copyToBytes(byte): void

Parameters

NameType
byteDataView

Returns

void

Defined in

src/math/Vector3.ts:1016


crossProduct

crossProduct(a, target?): Vector3

You take the cross product of two vectors, The cross product is going to be the perpendicular vector between these two vectors

Parameters

NameTypeDefault valueDescription
aVector3undefinedTake the cross product of another vector
targetVector3null-

Returns

Vector3

Vector3 returns the cross product vector

Defined in

src/math/Vector3.ts:1028


crossVectors

crossVectors(a, b): this

Parameters

NameType
aVector3
bVector3

Returns

this

Defined in

src/math/Vector3.ts:1037


multiplyScalar

multiplyScalar(scalar): Vector3

Parameters

NameType
scalarnumber

Returns

Vector3

Defined in

src/math/Vector3.ts:1042


setFromArray

setFromArray(array, firstElementPos?): void

Parameters

NameTypeDefault value
arraynumber[]undefined
firstElementPosnumber0

Returns

void

Defined in

src/math/Vector3.ts:1050


divideScalar

divideScalar(scalar): Vector3

Parameters

NameType
scalarany

Returns

Vector3

Defined in

src/math/Vector3.ts:1056


clampLength

clampLength(min, max): Vector3

Parameters

NameType
minnumber
maxnumber

Returns

Vector3

Defined in

src/math/Vector3.ts:1060


setScalar

setScalar(value): Vector3

Parameters

NameType
valuenumber

Returns

Vector3

Defined in

src/math/Vector3.ts:1065


pointInsideTriangle

pointInsideTriangle(pt, pt0, pt1, pt2): boolean

Parameters

NameType
ptVector3
pt0Vector3
pt1Vector3
pt2Vector3

Returns

boolean

Defined in

src/math/Vector3.ts:1094


serialize

serialize(position): Vector3

Parameters

NameType
positionVector3

Returns

Vector3

Defined in

src/math/Vector3.ts:1123