SFSVector3

Represents a vector/point in a 3D space.


This class is used to represent 3D positions and vectors.

Constructor

new SFSVector3(x, y, z)

Creates a new instance of the SFSVector3 class.
Parameters:
NameTypeDescription
xnumberThe vector component along the X axis.
ynumberThe vector component along the Y axis.
znumberThe vector component along the Z axis.

Members

(readonly) isNormalized :boolean

Indicates if the vector is normalized, i.e. its length is approximately equal to 1.
Type:
  • boolean

(readonly) length :number

The length (magnitude) of the vector.
Type:
  • number

x :number

The vector component along the X axis.
Type:
  • number

y :number

The vector component along the Y axis.
Type:
  • number

z :number

The vector component along the Z axis.
Type:
  • number

Methods

abs() → {SFSVector3}

Returns a new vector with all components in absolute values.
Returns:
A new vector with absolute components.
Type: 
SFSVector3

ceil() → {SFSVector3}

Returns a new vector with all components rounded up to the nearest integer.
Returns:
A new vector with rounded up components.
Type: 
SFSVector3

cross(vec) → {SFSVector3}

Returns the cross product of this vector and the passed vector.

The cross product is a vector perpendicular to both vectors.

Parameters:
NameTypeDescription
vecSFSVector3The vector to compute the cross product with.
Returns:
A new vector representing the cross product of the vectors.
Type: 
SFSVector3

distanceSquaredTo(vec) → {number}

Returns the squared distance between this vector and the passed vector.

This method is more efficient than SFSVector3#distanceTo method when comparing distances.

Parameters:
NameTypeDescription
vecSFSVector3The vector to measure the squared distance from.
Returns:
The squared distance between the vectors.
Type: 
number

distanceTo(vec) → {number}

Returns the Euclidean distance between this vector and the passed vector.
Parameters:
NameTypeDescription
vecSFSVector3The vector to measure the distance from.
Returns:
The distance between the vectors.
Type: 
number

div(vec) → {SFSVector3}

Returns a new vector that is the component-wise division of this vector by the passed vector.
Parameters:
NameTypeDescription
vecSFSVector3The vector to divide this vector by.
Returns:
A new vector representing the component-wise division of the two vectors.
Type: 
SFSVector3

dot(vec) → {number}

Returns the dot product of this vector and the passed vector.

The dot product will be 0 for a right angle (90 degrees), greater than 0 for angles narrower than 90 degrees and lower than 0 for angles wider than 90 degrees.

When using unit (normalized) vectors, the result will always be between -1.0 (180 degrees angle), when the vectors are facing opposite directions, and 1.0 (0 degrees angle) when the vectors are aligned.

Parameters:
NameTypeDescription
vecSFSVector3The vector to compute the dot product with.
Returns:
The dot product of the vectors.
Type: 
number

floor() → {SFSVector3}

Returns a new vector with all components rounded down to the nearest integer.
Returns:
A new vector with rounded down components.
Type: 
SFSVector3

lerp(vec, weight) → {SFSVector3}

Returns the result of the linear interpolation between this vector and the passed vector by the passe weight.

The weight range is 0.0 to 1.0, representing the amount of interpolation. Values outside this range will extrapolate.

Parameters:
NameTypeDescription
vecSFSVector3The target vector to interpolate towards.
weightnumberThe interpolation weight (0.0 = this vector, 1.0 = target vector).
Returns:
A new interpolated vector.
Type: 
SFSVector3

max(vec) → {SFSVector3}

Returns a new vector with the component-wise maximum of this vector and the passed vector.
Parameters:
NameTypeDescription
vecSFSVector3The vector to compare to.
Returns:
A new vector with the maximum components of the vectors.
Type: 
SFSVector3

min(vec) → {SFSVector3}

Returns a new vector with the component-wise minimum of this vector and the passed vector.
Parameters:
NameTypeDescription
vecSFSVector3The vector to compare to.
Returns:
A new vector with the minimum components of the vectors.
Type: 
SFSVector3

mult(vec) → {SFSVector3}

Returns a new vector that is the component-wise multiplication of this vector and the passed vector.
Parameters:
NameTypeDescription
vecSFSVector3The vector to multiply this vector by.
Returns:
A new vector representing the component-wise product of the two vectors.
Type: 
SFSVector3

normalize() → {SFSVector3}

Returns a new vector that is the normalized (unit length) version of this vector.

If this vector has zero length, returns a zero vector.

Returns:
A new normalized vector.
Type: 
SFSVector3

rotate(axis, angle) → {SFSVector3}

Returns a new vector that is the result of rotating this vector by the passed angle.
Parameters:
NameTypeDescription
axisSFSVector3The axis to rotate the vector around (must be a normalized vector).
anglenumberThe angle to rotate the vector by, in radians.
Returns:
A new rotated vector.
Type: 
SFSVector3

round() → {SFSVector3}

Returns a new vector with all components rounded to the nearest integer, with halfway cases rounded away from zero.
Returns:
A new vector with rounded components.
Type: 
SFSVector3

sub(vec) → {SFSVector3}

Returns a new vector that is the result of subtracting the passed vector from this vector.
Parameters:
NameTypeDescription
vecSFSVector3The vector to subtract from this vector.
Returns:
A new vector representing the difference between the two vectors.
Type: 
SFSVector3

sum(vec) → {SFSVector3}

Returns a new vector that is the sum of this vector and the passed vector.
Parameters:
NameTypeDescription
vecSFSVector3The vector to sum to this vector.
Returns:
A new vector representing the sum of the two vectors.
Type: 
SFSVector3

toString() → {string}

Returns a string containing the X, Y and Z components of the vector.
Returns:
The string representation of the SFSVector3 object.
Type: 
string