Skip to content
Vector4

[Basic Type](../groups/Basic Type.Basic Type.md) / Vector4

Vector4 Class ​

Homogeneous vector


A 4D homogeneous vector composed of components (x, y, z, w)

Table of contents ​

Properties ​

w: number
w weight
x: number
x weight
y: number
y weight
z: number
z weight

Accessors ​

length(): number
Calculate vector length (modulus)
magnitude(a: Vector4): number other
Vector length
negative(): Vector4
Return the new vector with the inverse of each component
normalized(): Vector4
Return a normalized new vector without affecting the current vector
sqrLength(): number
Calculate the square of vector length (modulus)
sqrMagnitude(a: Vector4): number other
Square of vector length
negOne(): Vector4
(-1, -1, -1, -1)
one(): Vector4
(1, 1, 1, 1)
zero(): Vector4
(0, 0, 0, 0)

Methods ​

add(a: Vector4, b: Vector4, outer?: Vector4): Vector4 other
Add two vectors together
clone(a: Vector4): Vector4 other
Obtain a copy of the specified vector
divide(a: Vector4, b: Vector4, outer?: Vector4): Vector4 other
Traverse each component of vector a and divide it by the number b
equals(a: Vector4, b: Vector4, epsilon?: number): boolean other
Determine whether two vectors are approximately equivalent in excluding floating-point errors
fromString(str: string, outer?: Vector4): Vector4 other
Create a Vector4 object from a string
multiply(a: Vector4, b: Vector4, outer?: Vector4): Vector4 other
Multiply each component of vector a by scalar b
normalize(a: Vector4, outer?: Vector4): Vector4 other
normalized vector
strictEquals(a: Vector4, b: Vector4): boolean other
Determine whether two vectors are equal
subtract(a: Vector4, b: Vector4, outer?: Vector4): Vector4 other
Subtract vector b from vector a
toString(): string other
Output as formatted string
add(a: Vector4, b: Vector4, outer?: Vector4): Vector4 other
Add two vectors together
ceil(a: Vector4, outer?: Vector4): Vector4 other
Element by element vector rounding up
clone(a: Vector4): Vector4 other
Obtain a copy of the specified vector
copy(a: Vector4, b: Vector4): Vector4 other
Assign the value of vector a to vector b
distance(a: Vector4, b: Vector4): number other
Euclidean distance between two vectors
divide(a: Vector4, b: Vector4, outer?: Vector4): Vector4 other
Traverse each component of vector a and divide it by the number b
dot(a: Vector4, b: Vector4): number other
Dot product
equals(a: Vector4, b: Vector4, epsilon?: number): boolean other
Determine whether two vectors are approximately equivalent in excluding floating-point errors
floor(a: Vector4, outer?: Vector4): Vector4 other
Rounding down the element by element vector
fromString(str: string, outer?: Vector4): Vector4 other
Create a Vector4 object from a string
invert(a: Vector4, outer?: Vector4): Vector4 other
Take the reciprocal of the vector element by element, and return Infinity when it approaches 0
invertSafe(a: Vector4, outer?: Vector4, epsilon?: number): Vector4 other
Take the reciprocal of the vector element by element, and return 0 when it approaches 0
lerp(a: Vector4, b: Vector4, t: number, outer?: Vector4): Vector4 other
Linear interpolation for each element of vector a: a+t * (b-a)
magnitude(a: Vector4): number other
Vector length
max(a: Vector4, b: Vector4, outer?: Vector4): Vector4 other
Maximum value of element by element vector
min(a: Vector4, b: Vector4, outer?: Vector4): Vector4 other
Minimum value of element by element vector
moveTowards(current: Vector4, target: Vector4, maxDistanceDelta: number, outer?: Vector4): Vector4 other
Move to the target vector
multiply(a: Vector4, b: Vector4, outer?: Vector4): Vector4 other
Multiply each component of vector a by scalar b
negate(a: Vector4, outer?: Vector4): Vector4 other
Take negative vectors element by element
normalize(a: Vector4, outer?: Vector4): Vector4 other
normalized vector
round(a: Vector4, outer?: Vector4): Vector4 other
Element by Element Vector Rounding rounding
set(a: Vector4, x: number, y: number, z: number, w: number): Vector4 other
Set vector values
sqrMagnitude(a: Vector4): number other
Square of vector length
squaredDistance(a: Vector4, b: Vector4): number other
The squared Euclidean distance between two vectors
strictEquals(a: Vector4, b: Vector4): boolean other
Determine whether two vectors are equal
subtract(a: Vector4, b: Vector4, outer?: Vector4): Vector4 other
Subtract vector b from vector a

Set x, y, z, w with the given value of x

Parameters ​

x? numberUsage: Given x value default: 0.0 range: No restrictions type: Floating point number

• new Vector4(x, y, z, w)

Construct a new Vector4 using the given x, y, z, and w components

Parameters ​

x numberUsage: Given x value default: 0.0 range: No restrictions type: Floating point number
y numberUsage: Given y value default: 0.0 range: No restrictions type: Floating point number
z numberUsage: Given z value default: 0.0 range: No restrictions type: Floating point number
w numberUsage: Given w value default: 0.0 range: No restrictions type: Floating point number

Properties ​

w ​

• w: number

w weight


x ​

• x: number

x weight


y ​

• y: number

y weight


z ​

• z: number

z weight

Accessors ​

length ​

• get length(): number

Calculate vector length (modulus)

Returns ​

number

magnitude ​

• get magnitude(): number

Calculate the length of a vector

Parameters ​

a Vector4Usage: vector a

Returns ​

numberVector length

negative ​

• get negative(): Vector4

Return the new vector with the inverse of each component

Returns ​

Vector4

normalized ​

• get normalized(): Vector4

Return a normalized new vector without affecting the current vector

Returns ​

Vector4

sqrLength ​

• get sqrLength(): number

Calculate the square of vector length (modulus)

Returns ​

number

sqrMagnitude ​

• get sqrMagnitude(): number

Calculate the length square of a vector

Parameters ​

a Vector4Usage: vector a

Returns ​

numberSquare of vector length

negOne ​

• Static get negOne(): Vector4

(-1, -1, -1, -1)

Returns ​

Vector4

one ​

• Static get one(): Vector4

(1, 1, 1, 1)

Returns ​

Vector4

zero ​

• Static get zero(): Vector4

(0, 0, 0, 0)

Returns ​

Vector4

Methods ​

add ​

• add(v): Vector4 other

Add a vector

Parameters ​

a Vector4Usage: vector a
b Vector4Usage: vector b
outer? Vector4Usage: Vector4 object receiving results default: null

Returns ​

Vector4The result of addition is Vector4 object

Parameters ​

v Vector4Usage: vector object for addition

clone ​

• clone(): Vector4 other

Clone the current vector

Parameters ​

a Vector4Usage: vector a

Returns ​

Vector4Cloned new Vector4 object

divide ​

• divide(v): Vector4 other

Divide each component by the parameter

Parameters ​

a Vector4Usage: vector a
b numberUsage: number b
range: unlimited type: floating-point number
outer? Vector4Usage: Vector4 object receiving results default: null

Returns ​

Vector4The result of division is Vector4 object

• Static divide(a, b, outer?): Vector4 other

Vector a divided by vector b

outer It is an optional parameter. The function is that when an outer is passed in, the calculation result will be assigned to the outer. (The incoming outer vector cannot be null/undefined)

Parameters ​

a Vector4Usage: vector a
b Vector4Usage: vector b
outer? Vector4Usage: Vector4 object receiving results default: null

Returns ​

Vector4The result of division is Vector4 object

Parameters ​

v numberUsage: Dividing vector objects range: Unrestricted type: Floating point value
Determine whether the current vector is equal to vector a within the error range

Parameters ​

a Vector4Usage: vector a
epsilon? numberUsage: Minimum error count default: MathUtil EPSILON
range: It is recommended to pass in a value less than 1. Type: Floating point number

Returns ​

booleanIs it equal

fromString ​

• fromString(str): void other

Read string data

Parameters ​

str stringUsage: Vector a range: "0.000000, 0.000000, 0.000000, 0.000000"
outer? Vector4Usage: Vector4 object receiving results default: null

Returns ​

Vector4Newly created Vector4 object

Parameters ​

str stringUsage: Read string range: "0.000000, 0.000000, 0.000000, 0.000000"

multiply ​

• multiply(v): Vector4 other

Multiply by a vector

Parameters ​

a Vector4Usage: vector a
b numberUsage: number b
range: unlimited type: floating-point number
outer? Vector4Usage: Vector4 object receiving results default: null

Returns ​

Vector4The result of multiplication is Vector4 object

• Static multiply(a, b, outer?): Vector4 other

Multiply vector a by vector b

outer It is an optional parameter. The function is that when an outer is passed in, the calculation result will be assigned to the outer. (The incoming outer vector cannot be null/undefined)

Parameters ​

a Vector4Usage: vector a
b Vector4Usage: vector b
outer? Vector4Usage: Vector4 object receiving results default: null

Returns ​

Vector4The result of multiplication is Vector4 object

Parameters ​

v Vector4Usage: Multiplying vector objects
Normalize the current vector

Returns ​

Vector4Normalized self object

strictEquals ​

• strictEquals(a): boolean other

Determine whether the current vector is equal to vector a

Parameters ​

a Vector4Usage: vector a
b Vector4Usage: vector b

Returns ​

booleanIs it equal

subtract ​

• subtract(v): Vector4 other

Subtract a vector

Parameters ​

a Vector4Usage: vector a
b Vector4Usage: vector b
outer? Vector4Usage: Vector4 object receiving results default: null

Returns ​

Vector4Subtraction result Vector4 object

Parameters ​

v Vector4Usage: Subtracting vector objects

toString ​

• toString(): string other

Output as formatted string

Returns ​

stringVector4 String of the object value

add ​

• Static add(a, b, outer?): Vector4 other

Add two vectors together

outer It is an optional parameter. The function is that when an outer is passed in, the calculation result will be assigned to the outer. (The incoming outer vector cannot be null/undefined)

Parameters ​

a Vector4Usage: vector a
b Vector4Usage: vector b
outer? Vector4Usage: Vector4 object receiving results default: null

Returns ​

Vector4The result of addition is Vector4 object

ceil ​

• Static ceil(a, outer?): Vector4 other

Element by element vector rounding up

Parameters ​

a Vector4Usage: vector a
outer? Vector4Usage: Vector4 object receiving results default: null

Returns ​

Vector4Vector4 object obtained by rounding up every element

outer It is an optional parameter. The function is that when an outer is passed in, the calculation result will be assigned to the outer. (The incoming outer vector cannot be null/undefined)


clone ​

• Static clone(a): Vector4 other

Obtain a copy of the specified vector

Parameters ​

a Vector4Usage: vector a

Returns ​

Vector4Cloned new Vector4 object

copy ​

• Static copy(a, b): Vector4 other

Assign the value of vector a to vector b

Parameters ​

a Vector4Usage: vector a
b Vector4Usage: vector b

Returns ​

Vector4Vector a

distance ​

• Static distance(a, b): number other

Euclidean distance between two vectors

Parameters ​

a Vector4Usage: vector a
b Vector4Usage: vector b

Returns ​

numberEuclidean distance between two vectors

divide ​

• Static divide(a, b, outer?): Vector4 other

Traverse each component of vector a and divide it by the number b

outer It is an optional parameter. The function is that when an outer is passed in, the calculation result will be assigned to the outer. (The incoming outer vector cannot be null/undefined)

Parameters ​

a Vector4Usage: vector a
b numberUsage: number b
range: unlimited type: floating-point number
outer? Vector4Usage: Vector4 object receiving results default: null

Returns ​

Vector4The result of division is Vector4 object

• Static divide(a, b, outer?): Vector4 other

Vector a divided by vector b

outer It is an optional parameter. The function is that when an outer is passed in, the calculation result will be assigned to the outer. (The incoming outer vector cannot be null/undefined)

Parameters ​

a Vector4Usage: vector a
b Vector4Usage: vector b
outer? Vector4Usage: Vector4 object receiving results default: null

Returns ​

Vector4The result of division is Vector4 object

dot ​

• Static dot(a, b): number other

Dot product

Parameters ​

a Vector4Usage: vector a
b Vector4Usage: vector b

Returns ​

numberVector dot product

equals ​

• Static equals(a, b, epsilon?): boolean other

Determine whether two vectors are approximately equivalent in excluding floating-point errors

Parameters ​

a Vector4Usage: vector a
b Vector4Usage: vector b
epsilon? numberUsage: Minimum error object default: 1. e-8
range: It is recommended to pass a value less than 1. Type: Floating point number

Returns ​

booleanIs it equal

floor ​

• Static floor(a, outer?): Vector4 other

Rounding down the element by element vector

Parameters ​

a Vector4Usage: vector a
outer? Vector4Usage: Vector4 object receiving results default: null

Returns ​

Vector4Vector4 object obtained by rounding down element by element

outer It is an optional parameter. The function is that when an outer is passed in, the calculation result will be assigned to the outer. (The incoming outer vector cannot be null/undefined)


fromString ​

• Static fromString(str, outer?): Vector4 other

Create a Vector4 object from a string

outer It is an optional parameter. The function is that when an outer is passed in, the calculation result will be assigned to the outer. (The incoming outer vector cannot be null/undefined)

Parameters ​

str stringUsage: Vector a range: "0.000000, 0.000000, 0.000000, 0.000000"
outer? Vector4Usage: Vector4 object receiving results default: null

Returns ​

Vector4Newly created Vector4 object

invert ​

• Static invert(a, outer?): Vector4 other

Take the reciprocal of the vector element by element, and return Infinity when it approaches 0

Parameters ​

a Vector4Usage: vector a
outer? Vector4Usage: Vector4 object receiving results default: null

Returns ​

Vector4Vector4 object obtained by taking the reciprocal of each element

outer It is an optional parameter. The function is that when an outer is passed in, the calculation result will be assigned to the outer. (The incoming outer vector cannot be null/undefined)


invertSafe ​

• Static invertSafe(a, outer?, epsilon?): Vector4 other

Take the reciprocal of the vector element by element, and return 0 when it approaches 0

Parameters ​

a Vector4Usage: vector a
outer? Vector4Usage: Vector4 object receiving results default: null
epsilon? numberUsage: Minimum error count default: MathUtil.EPSILON
range: It is recommended to pass in a value less than 1. Type: Floating point number

Returns ​

Vector4Vector4 object obtained by taking the reciprocal of each element

outer It is an optional parameter. The function is that when an outer is passed in, the calculation result will be assigned to the outer. (The incoming outer vector cannot be null/undefined)


lerp ​

• Static lerp(a, b, t, outer?): Vector4 other

Linear interpolation for each element of vector a: a+t * (b-a)

Parameters ​

a Vector4Usage: vector a
b Vector4Usage: vector b
t numberUsage: Interpolation
range: [0,1] type: Floating point number
outer? Vector4Usage: Vector4 object receiving results default: null

Returns ​

Vector4Interpolated Vector4 vector

outer It is an optional parameter. The function is that when an outer is passed in, the calculation result will be assigned to the outer. (The incoming outer vector cannot be null/undefined)


magnitude ​

• Static magnitude(a): number other

Vector length

Parameters ​

a Vector4Usage: vector a

Returns ​

numberVector length

max ​

• Static max(a, b, outer?): Vector4 other

Maximum value of element by element vector

Parameters ​

a Vector4Usage: vector a
b Vector4Usage: vector b
outer? Vector4Usage: Vector4 object receiving results default: null

Returns ​

Vector4Vector4 object obtained by taking the maximum value element by element

outer It is an optional parameter. The function is that when an outer is passed in, the calculation result will be assigned to the outer. (The incoming outer vector cannot be null/undefined)


min ​

• Static min(a, b, outer?): Vector4 other

Minimum value of element by element vector

Parameters ​

a Vector4Usage: vector a
b Vector4Usage: vector b
outer? Vector4Usage: Vector4 object receiving results default: null

Returns ​

Vector4Vector4 object obtained by taking the minimum value of each element vector

outer It is an optional parameter. The function is that when an outer is passed in, the calculation result will be assigned to the outer. (The incoming outer vector cannot be null/undefined)


moveTowards ​

• Static moveTowards(current, target, maxDistanceDelta, outer?): Vector4 other

Move to the target vector

Parameters ​

current Vector4Usage: Current vector
target Vector4Usage: target vector
maxDistanceDelta numberUsage: Maximum average moving distance
range: Unrestricted type: Floating point number
outer? Vector4Usage: Vector4 object receiving results default: null

Returns ​

Vector4Position after moving

outer It is an optional parameter. The function is that when an outer is passed in, the calculation result will be assigned to the outer. (The incoming outer vector cannot be null/undefined)


multiply ​

• Static multiply(a, b, outer?): Vector4 other

Multiply each component of vector a by scalar b

outer It is an optional parameter. The function is that when an outer is passed in, the calculation result will be assigned to the outer. (The incoming outer vector cannot be null/undefined)

Parameters ​

a Vector4Usage: vector a
b numberUsage: number b
range: unlimited type: floating-point number
outer? Vector4Usage: Vector4 object receiving results default: null

Returns ​

Vector4The result of multiplication is Vector4 object

• Static multiply(a, b, outer?): Vector4 other

Multiply vector a by vector b

outer It is an optional parameter. The function is that when an outer is passed in, the calculation result will be assigned to the outer. (The incoming outer vector cannot be null/undefined)

Parameters ​

a Vector4Usage: vector a
b Vector4Usage: vector b
outer? Vector4Usage: Vector4 object receiving results default: null

Returns ​

Vector4The result of multiplication is Vector4 object

negate ​

• Static negate(a, outer?): Vector4 other

Take negative vectors element by element

Parameters ​

a Vector4Usage: vector a
outer? Vector4Usage: Vector4 object receiving results default: null

Returns ​

Vector4Vector4 object obtained by taking negative values element by element

outer It is an optional parameter. The function is that when an outer is passed in, the calculation result will be assigned to the outer. (The incoming outer vector cannot be null/undefined)


normalize ​

• Static normalize(a, outer?): Vector4 other

normalized vector

Parameters ​

a Vector4Usage: vector a
outer? Vector4Usage: Vector4 object receiving results default: null

Returns ​

Vector4Normalized Vector4 object

outer It is an optional parameter. The function is that when an outer is passed in, the calculation result will be assigned to the outer. (The incoming outer vector cannot be null/undefined)


round ​

• Static round(a, outer?): Vector4 other

Element by Element Vector Rounding rounding

Parameters ​

a Vector4Usage: vector a
outer? Vector4Usage: Vector4 object receiving results default: null

Returns ​

Vector4Vector4 object obtained by rounding elements to the nearest integer

outer It is an optional parameter. The function is that when an outer is passed in, the calculation result will be assigned to the outer. (The incoming outer vector cannot be null/undefined)


set ​

• Static set(a, x, y, z, w): Vector4 other

Set vector values

Parameters ​

a Vector4Usage: vector a
x numberx Component
range: unlimited type: floating-point number
y numbery Component
range: unlimited type: floating-point number
z numberz Component
range: unlimited type: floating-point number
w numberw Component
range: unlimited type: floating-point number

Returns ​

Vector4Modified vector a

sqrMagnitude ​

• Static sqrMagnitude(a): number other

Square of vector length

Parameters ​

a Vector4Usage: vector a

Returns ​

numberSquare of vector length

squaredDistance ​

• Static squaredDistance(a, b): number other

The squared Euclidean distance between two vectors

Parameters ​

a Vector4Usage: vector a
b Vector4Usage: vector b

Returns ​

numberThe squared Euclidean distance between two vectors

strictEquals ​

• Static strictEquals(a, b): boolean other

Determine whether two vectors are equal

Parameters ​

a Vector4Usage: vector a
b Vector4Usage: vector b

Returns ​

booleanIs it equal

subtract ​

• Static subtract(a, b, outer?): Vector4 other

Subtract vector b from vector a

outer It is an optional parameter. The function is that when an outer is passed in, the calculation result will be assigned to the outer. (The incoming outer vector cannot be null/undefined)

Parameters ​

a Vector4Usage: vector a
b Vector4Usage: vector b
outer? Vector4Usage: Vector4 object receiving results default: null

Returns ​

Vector4Subtraction result Vector4 object