[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? number | Usage: 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 number | Usage: Given x value default: 0.0 range: No restrictions type: Floating point number |
|---|---|
y number | Usage: Given y value default: 0.0 range: No restrictions type: Floating point number |
z number | Usage: Given z value default: 0.0 range: No restrictions type: Floating point number |
w number | Usage: 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
• | ||
|---|---|---|
Calculate vector length (modulus) Returns
|
magnitude
• get magnitude(): number
Calculate the length of a vector
Parameters
a Vector4 | Usage: vector a |
|---|
Returns
number | Vector length |
|---|
negative
• | ||
|---|---|---|
Return the new vector with the inverse of each component Returns
|
normalized
• | ||
|---|---|---|
Return a normalized new vector without affecting the current vector Returns
|
sqrLength
• | ||
|---|---|---|
Calculate the square of vector length (modulus) Returns
|
sqrMagnitude
• get sqrMagnitude(): number
Calculate the length square of a vector
Parameters
a Vector4 | Usage: vector a |
|---|
Returns
number | Square of vector length |
|---|
negOne
• | ||
|---|---|---|
(-1, -1, -1, -1) Returns
|
one
• | ||
|---|---|---|
(1, 1, 1, 1) Returns
|
zero
• |
|---|
(0, 0, 0, 0) Returns |
Vector4 |
|---|
Methods
add
• add(v): Vector4 other
Add a vector
Parameters
a Vector4 | Usage: vector a |
|---|---|
b Vector4 | Usage: vector b |
outer? Vector4 | Usage: Vector4 object receiving results default: null |
Returns
Vector4 | The result of addition is Vector4 object |
|---|
Parameters
v Vector4 | Usage: vector object for addition |
|---|
clone
• clone(): Vector4 other
Clone the current vector
Parameters
a Vector4 | Usage: vector a |
|---|
Returns
Vector4 | Cloned new Vector4 object |
|---|
divide
• divide(v): Vector4 other
Divide each component by the parameter
Parameters
a Vector4 | Usage: vector a |
|---|---|
b number | Usage: number b range: unlimited type: floating-point number |
outer? Vector4 | Usage: Vector4 object receiving results default: null |
Returns
Vector4 | The 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 Vector4 | Usage: vector a |
|---|---|
b Vector4 | Usage: vector b |
outer? Vector4 | Usage: Vector4 object receiving results default: null |
Returns
Vector4 | The result of division is Vector4 object |
|---|
Parameters
v number | Usage: 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 Vector4 | Usage: vector a |
|---|---|
epsilon? number | Usage: Minimum error count default: MathUtil EPSILON range: It is recommended to pass in a value less than 1. Type: Floating point number |
Returns
boolean | Is it equal |
|---|
fromString
• fromString(str): void other
Read string data
Parameters
str string | Usage: Vector a range: "0.000000, 0.000000, 0.000000, 0.000000" |
|---|---|
outer? Vector4 | Usage: Vector4 object receiving results default: null |
Returns
Vector4 | Newly created Vector4 object |
|---|
Parameters
str string | Usage: Read string range: "0.000000, 0.000000, 0.000000, 0.000000" |
|---|
multiply
• multiply(v): Vector4 other
Multiply by a vector
Parameters
a Vector4 | Usage: vector a |
|---|---|
b number | Usage: number b range: unlimited type: floating-point number |
outer? Vector4 | Usage: Vector4 object receiving results default: null |
Returns
Vector4 | The 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 Vector4 | Usage: vector a |
|---|---|
b Vector4 | Usage: vector b |
outer? Vector4 | Usage: Vector4 object receiving results default: null |
Returns
Vector4 | The result of multiplication is Vector4 object |
|---|
Parameters
v Vector4 | Usage: Multiplying vector objects |
|---|---|
| Normalize the current vector |
Returns
Vector4 | Normalized self object |
|---|
strictEquals
• strictEquals(a): boolean other
Determine whether the current vector is equal to vector a
Parameters
a Vector4 | Usage: vector a |
|---|---|
b Vector4 | Usage: vector b |
Returns
boolean | Is it equal |
|---|
subtract
• subtract(v): Vector4 other
Subtract a vector
Parameters
a Vector4 | Usage: vector a |
|---|---|
b Vector4 | Usage: vector b |
outer? Vector4 | Usage: Vector4 object receiving results default: null |
Returns
Vector4 | Subtraction result Vector4 object |
|---|
Parameters
v Vector4 | Usage: Subtracting vector objects |
|---|
toString
• toString(): string other
Output as formatted string
Returns
string | Vector4 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 Vector4 | Usage: vector a |
|---|---|
b Vector4 | Usage: vector b |
outer? Vector4 | Usage: Vector4 object receiving results default: null |
Returns
Vector4 | The result of addition is Vector4 object |
|---|
ceil
• Static ceil(a, outer?): Vector4 other
Element by element vector rounding up
Parameters
a Vector4 | Usage: vector a |
|---|---|
outer? Vector4 | Usage: Vector4 object receiving results default: null |
Returns
Vector4 | Vector4 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 Vector4 | Usage: vector a |
|---|
Returns
Vector4 | Cloned new Vector4 object |
|---|
copy
• Static copy(a, b): Vector4 other
Assign the value of vector a to vector b
Parameters
a Vector4 | Usage: vector a |
|---|---|
b Vector4 | Usage: vector b |
Returns
Vector4 | Vector a |
|---|
distance
• Static distance(a, b): number other
Euclidean distance between two vectors
Parameters
a Vector4 | Usage: vector a |
|---|---|
b Vector4 | Usage: vector b |
Returns
number | Euclidean 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 Vector4 | Usage: vector a |
|---|---|
b number | Usage: number b range: unlimited type: floating-point number |
outer? Vector4 | Usage: Vector4 object receiving results default: null |
Returns
Vector4 | The 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 Vector4 | Usage: vector a |
|---|---|
b Vector4 | Usage: vector b |
outer? Vector4 | Usage: Vector4 object receiving results default: null |
Returns
Vector4 | The result of division is Vector4 object |
|---|
dot
• Static dot(a, b): number other
Dot product
Parameters
a Vector4 | Usage: vector a |
|---|---|
b Vector4 | Usage: vector b |
Returns
number | Vector dot product |
|---|
equals
• Static equals(a, b, epsilon?): boolean other
Determine whether two vectors are approximately equivalent in excluding floating-point errors
Parameters
a Vector4 | Usage: vector a |
|---|---|
b Vector4 | Usage: vector b |
epsilon? number | Usage: Minimum error object default: 1. e-8 range: It is recommended to pass a value less than 1. Type: Floating point number |
Returns
boolean | Is it equal |
|---|
floor
• Static floor(a, outer?): Vector4 other
Rounding down the element by element vector
Parameters
a Vector4 | Usage: vector a |
|---|---|
outer? Vector4 | Usage: Vector4 object receiving results default: null |
Returns
Vector4 | Vector4 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 string | Usage: Vector a range: "0.000000, 0.000000, 0.000000, 0.000000" |
|---|---|
outer? Vector4 | Usage: Vector4 object receiving results default: null |
Returns
Vector4 | Newly 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 Vector4 | Usage: vector a |
|---|---|
outer? Vector4 | Usage: Vector4 object receiving results default: null |
Returns
Vector4 | Vector4 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 Vector4 | Usage: vector a |
|---|---|
outer? Vector4 | Usage: Vector4 object receiving results default: null |
epsilon? number | Usage: Minimum error count default: MathUtil.EPSILON range: It is recommended to pass in a value less than 1. Type: Floating point number |
Returns
Vector4 | Vector4 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 Vector4 | Usage: vector a |
|---|---|
b Vector4 | Usage: vector b |
t number | Usage: Interpolation range: [0,1] type: Floating point number |
outer? Vector4 | Usage: Vector4 object receiving results default: null |
Returns
Vector4 | Interpolated 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 Vector4 | Usage: vector a |
|---|
Returns
number | Vector length |
|---|
max
• Static max(a, b, outer?): Vector4 other
Maximum value of element by element vector
Parameters
a Vector4 | Usage: vector a |
|---|---|
b Vector4 | Usage: vector b |
outer? Vector4 | Usage: Vector4 object receiving results default: null |
Returns
Vector4 | Vector4 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 Vector4 | Usage: vector a |
|---|---|
b Vector4 | Usage: vector b |
outer? Vector4 | Usage: Vector4 object receiving results default: null |
Returns
Vector4 | Vector4 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 Vector4 | Usage: Current vector |
|---|---|
target Vector4 | Usage: target vector |
maxDistanceDelta number | Usage: Maximum average moving distance range: Unrestricted type: Floating point number |
outer? Vector4 | Usage: Vector4 object receiving results default: null |
Returns
Vector4 | Position 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 Vector4 | Usage: vector a |
|---|---|
b number | Usage: number b range: unlimited type: floating-point number |
outer? Vector4 | Usage: Vector4 object receiving results default: null |
Returns
Vector4 | The 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 Vector4 | Usage: vector a |
|---|---|
b Vector4 | Usage: vector b |
outer? Vector4 | Usage: Vector4 object receiving results default: null |
Returns
Vector4 | The result of multiplication is Vector4 object |
|---|
negate
• Static negate(a, outer?): Vector4 other
Take negative vectors element by element
Parameters
a Vector4 | Usage: vector a |
|---|---|
outer? Vector4 | Usage: Vector4 object receiving results default: null |
Returns
Vector4 | Vector4 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 Vector4 | Usage: vector a |
|---|---|
outer? Vector4 | Usage: Vector4 object receiving results default: null |
Returns
Vector4 | Normalized 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 Vector4 | Usage: vector a |
|---|---|
outer? Vector4 | Usage: Vector4 object receiving results default: null |
Returns
Vector4 | Vector4 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 Vector4 | Usage: vector a |
|---|---|
x number | x Component range: unlimited type: floating-point number |
y number | y Component range: unlimited type: floating-point number |
z number | z Component range: unlimited type: floating-point number |
w number | w Component range: unlimited type: floating-point number |
Returns
Vector4 | Modified vector a |
|---|
sqrMagnitude
• Static sqrMagnitude(a): number other
Square of vector length
Parameters
a Vector4 | Usage: vector a |
|---|
Returns
number | Square of vector length |
|---|
squaredDistance
• Static squaredDistance(a, b): number other
The squared Euclidean distance between two vectors
Parameters
a Vector4 | Usage: vector a |
|---|---|
b Vector4 | Usage: vector b |
Returns
number | The squared Euclidean distance between two vectors |
|---|
strictEquals
• Static strictEquals(a, b): boolean other
Determine whether two vectors are equal
Parameters
a Vector4 | Usage: vector a |
|---|---|
b Vector4 | Usage: vector b |
Returns
boolean | Is 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 Vector4 | Usage: vector a |
|---|---|
b Vector4 | Usage: vector b |
outer? Vector4 | Usage: Vector4 object receiving results default: null |
Returns
Vector4 | Subtraction result Vector4 object |
|---|
Editor API