# Vector3

Objects

## Description

class Vector3

Represents a point in a 3D space.

## new Vector3(x, y, z)

Creates a new Vector3 object from the passed x, y, z (floats) coordinates.

A Vector3 is the main object used in 3D geometry.

It can represent etiher the coordinates of a point the space, either a direction.

#### Parameters

Name Type Description
x number The X coordinate to transform
y number The Y coordinate to transform
z number The Z coordinate to transform

## Members

### x : number

The first coordinate

### y : number

The second coordinate

### z : number

The third coordinate

## Methods

### toString() → string

Returns a string with the Vector3 coordinates.

### getClassName() → string

Returns the string "Vector3"

### getHashCode() → number

Returns the Vector hash code.

### asArray() → number[]

Returns a new array with three elements : the coordinates the Vector3.

### toArray(array, Float32Array, index) → Vector3

Populates the passed array or Float32Array from the passed index with the successive coordinates of the Vector3.

Returns the Vector3.

#### Parameters

Name Type Description
array number[] or Float32Array The given array of floats
optional index number default : 0 The given index

### toQuaternion() → Quaternion

Returns a new Quaternion object, computed from the Vector3 coordinates.

Adds the passed vector to the current Vector3.

Returns the updated Vector3.

#### Parameters

Name Type Description
otherVector Vector3 Another vector

Returns a new Vector3, result of the addition the current Vector3 and the passed vector.

#### Parameters

Name Type Description
otherVector Vector3 Another vector

Adds the current Vector3 to the passed one and stores the result in the vector "result".

Returns the current Vector3.

#### Parameters

Name Type Description
otherVector Vector3 Another vector
result Vector3 The vector to put the result into

### subtractInPlace(otherVector) → Vector3

Subtract the passed vector from the current Vector3.

Returns the updated Vector3.

#### Parameters

Name Type Description
otherVector Vector3 Another vector

### subtract(otherVector) → Vector3

Returns a new Vector3, result of the subtraction of the passed vector from the current Vector3.

#### Parameters

Name Type Description
otherVector Vector3 Another vector

### subtractToRef(otherVector, result) → Vector3

Subtracts the passed vector from the current Vector3 and stores the result in the vector "result".

Returns the current Vector3.

#### Parameters

Name Type Description
otherVector Vector3 Another vector
result Vector3 The vector to put the result into

### subtractFromFloats(x, y, z) → Vector3

Returns a new Vector3 set with the subtraction of the passed floats from the current Vector3 coordinates.

#### Parameters

Name Type Description
x number The X coordinate to transform
y number The Y coordinate to transform
z number The Z coordinate to transform

### subtractFromFloatsToRef(x, y, z, result) → Vector3

Subtracts the passed floats from the current Vector3 coordinates and set the passed vector "result" with this result.

Returns the current Vector3.

#### Parameters

Name Type Description
x number The X coordinate to transform
y number The Y coordinate to transform
z number The Z coordinate to transform

### negate() → Vector3

Returns a new Vector3 set with the current Vector3 negated coordinates.

### scaleInPlace(scale) → Vector3

Multiplies the Vector3 coordinates by the float "scale".

Returns the updated Vector3.

#### Parameters

Name Type Description
scale number The scaling factor

### scale(scale) → Vector3

Returns a new Vector3 set with the current Vector3 coordinates multiplied by the float "scale".

#### Parameters

Name Type Description
scale number The scaling factor

### scaleToRef(scale, result) → Vector3

Multiplies the current Vector3 coordinates by the float "scale" and stores the result in the passed vector "result" coordinates.

Returns the current Vector3.

#### Parameters

Name Type Description
scale number The scaling factor
result Vector3 The vector to put the result into

### equals(otherVector) → boolean

Boolean : True if the current Vector3 and the passed vector coordinates are strictly equal.

#### Parameters

Name Type Description
otherVector Vector3 Another vector

### equalsWithEpsilon(otherVector, epsilon) → boolean

Boolean : True if the current Vector3 and the passed vector coordinates are distant less than epsilon.

#### Parameters

Name Type Description
otherVector Vector3 Another vector
optional epsilon number

### equalsToFloats(x, y, z) → boolean

Boolean : True if the current Vector3 coordinate equal the passed floats.

#### Parameters

Name Type Description
x number The X coordinate to transform
y number The Y coordinate to transform
z number The Z coordinate to transform

### multiplyInPlace(otherVector) → Vector3

Muliplies the current Vector3 coordinates by the passed ones.

Returns the updated Vector3.

#### Parameters

Name Type Description
otherVector Vector3 Another vector

### multiply(otherVector) → Vector3

Returns a new Vector3, result of the multiplication of the current Vector3 by the passed vector.

#### Parameters

Name Type Description
otherVector Vector3 Another vector

### multiplyToRef(otherVector, result) → Vector3

Multiplies the current Vector3 by the passed one and stores the result in the passed vector "result".

Returns the current Vector3.

#### Parameters

Name Type Description
otherVector Vector3 Another vector
result Vector3 The vector to put the result into

### multiplyByFloats(x, y, z) → Vector3

Returns a new Vector3 set witth the result of the mulliplication of the current Vector3 coordinates by the passed floats.

#### Parameters

Name Type Description
x number The X coordinate to transform
y number The Y coordinate to transform
z number The Z coordinate to transform

### divide(otherVector) → Vector3

Returns a new Vector3 set witth the result of the division of the current Vector3 coordinates by the passed ones.

#### Parameters

Name Type Description
otherVector Vector3 Another vector

### divideToRef(otherVector, result) → Vector3

Divides the current Vector3 coordinates by the passed ones and stores the result in the passed vector "result".

Returns the current Vector3.

#### Parameters

Name Type Description
otherVector Vector3 Another vector
result Vector3 The vector to put the result into

### MinimizeInPlace(other) → Vector3

Updates the current Vector3 with the minimal coordinate values between its and the passed vector ones.

Returns the updated Vector3.

#### Parameters

Name Type Description
other Vector3 Another vector

### MaximizeInPlace(other) → Vector3

Updates the current Vector3 with the maximal coordinate values between its and the passed vector ones.

Returns the updated Vector3.

#### Parameters

Name Type Description
other Vector3 Another vector

### length() → number

Returns the length of the Vector3 (float).

### lengthSquared() → number

Returns the squared length of the Vector3 (float).

### normalize() → Vector3

Normalize the current Vector3.

Returns the updated Vector3.

### clone() → Vector3

Returns a new Vector3 copied from the current Vector3.

### copyFrom(source) → Vector3

Copies the passed vector coordinates to the current Vector3 ones.

Returns the updated Vector3.

#### Parameters

Name Type Description
source Vector3 The vector to project

### copyFromFloats(x, y, z) → Vector3

Copies the passed floats to the current Vector3 coordinates.

Returns the updated Vector3.

#### Parameters

Name Type Description
x number The X coordinate to transform
y number The Y coordinate to transform
z number The Z coordinate to transform

### set(x, y, z) → Vector3

Copies the passed floats to the current Vector3 coordinates.

Returns the updated Vector3.

#### Parameters

Name Type Description
x number The X coordinate to transform
y number The Y coordinate to transform
z number The Z coordinate to transform

### static GetClipFactor(vector0, vector1, axis, size) → number

*/

#### Parameters

Name Type Description
vector0 Vector3
vector1 Vector3
axis Vector3

### static FromArray(array, offset) → Vector3

Returns a new Vector3 set from the index "offset" of the passed array.

#### Parameters

Name Type Description
array ArrayLike<number> The given array of floats
optional offset number The first index of the array to look at

### static FromFloatArray(array, offset) → Vector3

Returns a new Vector3 set from the index "offset" of the passed Float32Array.

This function is deprecated. Use FromArray instead.

#### Parameters

Name Type Description
array Float32Array The given array of floats
optional offset number The first index of the array to look at

### static FromArrayToRef(array, offset, result) → void

Sets the passed vector "result" with the element values from the index "offset" of the passed array.

#### Parameters

Name Type Description
array ArrayLike<number> The given array of floats
offset number The first index of the array to look at
result Vector3 The vector to put the result into

### static FromFloatArrayToRef(array, offset, result) → void

Sets the passed vector "result" with the element values from the index "offset" of the passed Float32Array.

This function is deprecated. Use FromArrayToRef instead.

#### Parameters

Name Type Description
array Float32Array The given array of floats
offset number The first index of the array to look at
result Vector3 The vector to put the result into

### static FromFloatsToRef(x, y, z, result) → void

Sets the passed vector "result" with the passed floats.

#### Parameters

Name Type Description
x number The X coordinate to transform
y number The Y coordinate to transform
z number The Z coordinate to transform

### static Zero() → Vector3

Returns a new Vector3 set to (0.0, 0.0, 0.0).

### static Up() → Vector3

Returns a new Vector3 set to (0.0, 1.0, 0.0)

### static Forward() → Vector3

Returns a new Vector3 set to (0.0, 0.0, 1.0)

### static Right() → Vector3

Returns a new Vector3 set to (1.0, 0.0, 0.0)

### static Left() → Vector3

Returns a new Vector3 set to (-1.0, 0.0, 0.0)

### static TransformCoordinates(vector, transformation) → Vector3

Returns a new Vector3 set with the result of the transformation by the passed matrix of the passed vector.

This method computes tranformed coordinates only, not transformed direction vectors.

#### Parameters

Name Type Description
vector Vector3 The vector to project
transformation Matrix The transformation matrix

### static TransformCoordinatesToRef(vector, transformation, result) → void

Sets the passed vector "result" coordinates with the result of the transformation by the passed matrix of the passed vector.

This method computes tranformed coordinates only, not transformed direction vectors.

#### Parameters

Name Type Description
vector Vector3 The vector to project
transformation Matrix The transformation matrix
result Vector3 The vector to put the result into

### static TransformCoordinatesFromFloatsToRef(x, y, z, transformation, result) → void

Sets the passed vector "result" coordinates with the result of the transformation by the passed matrix of the passed floats (x, y, z).

This method computes tranformed coordinates only, not transformed direction vectors.

#### Parameters

Name Type Description
x number The X coordinate to transform
y number The Y coordinate to transform
z number The Z coordinate to transform
transformation Matrix The transformation matrix

### static TransformNormal(vector, transformation) → Vector3

Returns a new Vector3 set with the result of the normal transformation by the passed matrix of the passed vector.

This methods computes transformed normalized direction vectors only.

#### Parameters

Name Type Description
vector Vector3 The vector to project
transformation Matrix The transformation matrix

### static TransformNormalToRef(vector, transformation, result) → void

Sets the passed vector "result" with the result of the normal transformation by the passed matrix of the passed vector.

This methods computes transformed normalized direction vectors only.

#### Parameters

Name Type Description
vector Vector3 The vector to project
transformation Matrix The transformation matrix
result Vector3 The vector to put the result into

### static TransformNormalFromFloatsToRef(x, y, z, transformation, result) → void

Sets the passed vector "result" with the result of the normal transformation by the passed matrix of the passed floats (x, y, z).

This methods computes transformed normalized direction vectors only.

#### Parameters

Name Type Description
x number The X coordinate to transform
y number The Y coordinate to transform
z number The Z coordinate to transform
transformation Matrix The transformation matrix

### static CatmullRom(value1, value2, value3, value4, amount) → Vector3

Returns a new Vector3 located for "amount" on the CatmullRom interpolation spline defined by the vectors "value1", "value2", "value3", "value4".

#### Parameters

Name Type Description
value1 Vector3 first vector
value2 Vector3 second vector
value3 Vector3 The third position in the interpolation.
value4 Vector3 The fourth position in the interpolation.

### static Clamp(value, min, max) → Vector3

Returns a new Vector3 set with the coordinates of "value", if the vector "value" is in the cube defined by the vectors "min" and "max".

If a coordinate value of "value" is lower than one of the "min" coordinate, then this "value" coordinate is set with the "min" one.

If a coordinate value of "value" is greater than one of the "max" coordinate, then this "value" coordinate is set with the "max" one.

#### Parameters

Name Type Description
value Vector3 The value to clamp
min Vector3 The minimum value
max Vector3 The maximum value

### static Hermite(value1, tangent1, value2, tangent2, amount) → Vector3

Returns a new Vector3 located for "amount" (float) on the Hermite interpolation spline defined by the vectors "value1", "tangent1", "value2", "tangent2".

#### Parameters

Name Type Description
value1 Vector3 first vector
tangent1 Vector3 First source tangent vector.
value2 Vector3 second vector
tangent2 Vector3 Second source tangent vector.

### static Lerp(start, end, amount) → Vector3

Returns a new Vector3 located for "amount" (float) on the linear interpolation between the vectors "start" and "end".

#### Parameters

Name Type Description
start Vector3 interpolation start vector
end Vector3 interpolation end vector
amount number Weighting factor

### static LerpToRef(start, end, amount, result) → void

Sets the passed vector "result" with the result of the linear interpolation from the vector "start" for "amount" to the vector "end".

#### Parameters

Name Type Description
start Vector3 interpolation start vector
end Vector3 interpolation end vector
amount number Weighting factor

### static Dot(left, right) → number

Returns the dot product (float) between the vectors "left" and "right".

#### Parameters

Name Type Description
left Vector3 The vector to maximize
right Vector3 the vetor used to maximize

### static Cross(left, right) → Vector3

Returns a new Vector3 as the cross product of the vectors "left" and "right".

The cross product is then orthogonal to both "left" and "right".

#### Parameters

Name Type Description
left Vector3 The vector to maximize
right Vector3 the vetor used to maximize

### static CrossToRef(left, right, result) → void

Sets the passed vector "result" with the cross product of "left" and "right".

The cross product is then orthogonal to both "left" and "right".

#### Parameters

Name Type Description
left Vector3 The vector to maximize
right Vector3 the vetor used to maximize
result Vector3 The vector to put the result into

### static Normalize(vector) → Vector3

Returns a new Vector3 as the normalization of the passed vector.

#### Parameters

Name Type Description
vector Vector3 The vector to project

### static NormalizeToRef(vector, result) → void

Sets the passed vector "result" with the normalization of the passed first vector.

#### Parameters

Name Type Description
vector Vector3 The vector to project
result Vector3 The vector to put the result into

### static Project(vector, world, transform, viewport) → Vector3

Projects a 3D vector from object space into screen space.

#### Parameters

Name Type Description
vector Vector3 The vector to project
world Matrix The matrix representing the world matrix
transform Matrix

### static UnprojectFromTransform(source, viewportWidth, viewportHeight, world, transform) → Vector3

#### Parameters

Name Type Description
source Vector3 The vector to project
viewportWidth number The viewport width
viewportHeight number The viewport height
world Matrix The matrix representing the world matrix

### static Unproject(source, viewportWidth, viewportHeight, world, view, projection) → Vector3

Converts a 3D vector from screen space into world space.

#### Parameters

Name Type Description
source Vector3 The vector to project
viewportWidth number The viewport width
viewportHeight number The viewport height
world Matrix The matrix representing the world matrix
view Matrix The matrix representing the view matrix

### static Minimize(left, right) → Vector3

Minimizes the left vector with the right vector

#### Parameters

Name Type Description
left Vector3 The vector to maximize
right Vector3 the vetor used to maximize

### static Maximize(left, right) → Vector3

Maximizes the left vector with the right vector

#### Parameters

Name Type Description
left Vector3 The vector to maximize
right Vector3 the vetor used to maximize

### static Distance(value1, value2) → number

Returns the distance (float) between the vectors "value1" and "value2".

#### Parameters

Name Type Description
value1 Vector3 first vector
value2 Vector3 second vector

### static DistanceSquared(value1, value2) → number

Returns the squared distance (float) between the vectors "value1" and "value2".

#### Parameters

Name Type Description
value1 Vector3 first vector
value2 Vector3 second vector

### static Center(value1, value2) → Vector3

Returns a new Vector3 located at the center between "value1" and "value2".

#### Parameters

Name Type Description
value1 Vector3 first vector
value2 Vector3 second vector

### static RotationFromAxis(axis1, axis2, axis3) → Vector3

Given three orthogonal normalized left-handed oriented Vector3 axis in space (target system),

RotationFromAxis() returns the rotation Euler angles (ex : rotation.x, rotation.y, rotation.z) to apply

to something in order to rotate it from its local system to the given target system.

Note : axis1, axis2 and axis3 are normalized during this operation.

Returns a new Vector3.

#### Parameters

Name Type Description
axis1 Vector3
axis2 Vector3
axis3 Vector3

### static RotationFromAxisToRef(axis1, axis2, axis3, ref) → void

The same than RotationFromAxis but updates the passed ref Vector3 parameter instead of returning a new Vector3.

#### Parameters

Name Type Description
axis1 Vector3
axis2 Vector3
axis3 Vector3