Hierarchy

  • Vec3

Implements

  • Vector3

Constructors

  • Parameters

    • x: number
    • y: number
    • z: number

    Returns Vec3

  • Parameters

    Returns Vec3

  • Parameters

    • x: Vector3

    Returns Vec3

  • Parameters

    • x: Direction

    Returns Vec3

  • Parameters

    • x: number[]

    Returns Vec3

Properties

x: number
y: number
z: number
Down: Vec3
East: Vec3
North: Vec3
South: Vec3
Up: Vec3
West: Vec3
Zero: Vec3
_from: any

Methods

  • Adds another vector to the current vector.

    Parameters

    • x: number
    • y: number
    • z: number

    Returns Vec3

    The updated vector after addition.

  • Parameters

    Returns Vec3

  • Parameters

    • x: Vector3

    Returns Vec3

  • Parameters

    • x: Direction

    Returns Vec3

  • Parameters

    • x: number[]

    Returns Vec3

  • Computes the angle (in radians) between the current vector and another vector.

    Parameters

    • x: number
    • y: number
    • z: number

    Returns number

    The angle in radians between the two vectors. To convert to degrees, use: angleInDegrees = angleInRadians * (180 / Math.PI).

  • Parameters

    Returns number

  • Parameters

    • x: Vector3

    Returns number

  • Parameters

    • x: Direction

    Returns number

  • Parameters

    • x: number[]

    Returns number

  • Creates a copy of the current vector.

    Returns Vec3

    A new vector with the same values as the current vector.

  • Computes the cross product of the current vector with another vector.

    A cross product is a vector that is perpendicular to both vectors.

    Parameters

    • x: number
    • y: number
    • z: number

    Returns Vec3

    A new vector representing the cross product.

  • Parameters

    Returns Vec3

  • Parameters

    • x: Vector3

    Returns Vec3

  • Parameters

    • x: Direction

    Returns Vec3

  • Parameters

    • x: number[]

    Returns Vec3

  • Computes the distance between the current vector and another vector.

    Parameters

    • x: number
    • y: number
    • z: number

    Returns number

    The distance between the two vectors.

  • Parameters

    Returns number

  • Parameters

    • x: Vector3

    Returns number

  • Parameters

    • x: Direction

    Returns number

  • Parameters

    • x: number[]

    Returns number

  • Computes the squared distance between the current vector and another vector. This is faster than computing the actual distance and can be useful for comparison purposes.

    Parameters

    • x: number
    • y: number
    • z: number

    Returns number

    The squared distance between the two vectors.

  • Parameters

    Returns number

  • Parameters

    • x: Vector3

    Returns number

  • Parameters

    • x: Direction

    Returns number

  • Parameters

    • x: number[]

    Returns number

  • Calculates the shortest distance between a point (represented by this Vector3 instance) and a line segment.

    This method finds the perpendicular projection of the point onto the line defined by the segment. If this projection lies outside the line segment, then the method calculates the distance from the point to the nearest segment endpoint.

    Parameters

    • start: Vector3

      The starting point of the line segment.

    • end: Vector3

      The ending point of the line segment.

    Returns number

    The shortest distance between the point and the line segment.

  • Divides the current vector by another vector or scalar.

    Parameters

    • x: number
    • y: number
    • z: number

    Returns Vec3

    The updated vector after division.

  • Parameters

    Returns Vec3

  • Parameters

    • x: Vector3

    Returns Vec3

  • Parameters

    • x: Direction

    Returns Vec3

  • Parameters

    • x: number[]

    Returns Vec3

  • Parameters

    • x: number

    Returns Vec3

  • Computes the dot product of the current vector with another vector.

    Parameters

    • x: number
    • y: number
    • z: number

    Returns number

    The dot product of the two vectors.

  • Parameters

    Returns number

  • Parameters

    • x: Vector3

    Returns number

  • Parameters

    • x: Direction

    Returns number

  • Parameters

    • x: number[]

    Returns number

  • Checks if the current vector is equal to another vector.

    Parameters

    • x: number
    • y: number
    • z: number

    Returns boolean

  • Parameters

    Returns boolean

  • Parameters

    • x: Vector3

    Returns boolean

  • Parameters

    • x: Direction

    Returns boolean

  • Parameters

    • x: number[]

    Returns boolean

  • Checks if the current vector is equal to the zero vector.

    Returns boolean

    true if the vector is equal to the zero vector, else returns false.

  • Computes the length (magnitude) of the vector.

    Returns number

    The length of the vector.

  • Computes the squared length of the vector. This is faster than computing the actual length and can be useful for comparison purposes.

    Returns number

    The squared length of the vector.

  • Computes the linear interpolation between the current vector and another vector.

    Parameters

    • v: Vector3

      The other vector.

    • t: number

      The interpolation factor (0 <= t <= 1).

    Returns Vec3

    A new vector after performing the lerp operation.

  • Multiplies the current vector by another vector or scalar.

    Parameters

    • x: number
    • y: number
    • z: number

    Returns Vec3

    The updated vector after multiplication.

  • Parameters

    Returns Vec3

  • Parameters

    • x: Vector3

    Returns Vec3

  • Parameters

    • x: Direction

    Returns Vec3

  • Parameters

    • x: number[]

    Returns Vec3

  • Parameters

    • x: number

    Returns Vec3

  • Normalizes the vector to have a length (magnitude) of 1. Normalized vectors are often used as a direction vectors.

    Returns Vec3

    The normalized vector.

  • Computes the projection of the current vector onto another vector. This method finds how much of the current vector lies in the direction of vector v.

    Parameters

    • x: number
    • y: number
    • z: number

    Returns Vec3

    A new vector representing the projection of the current vector onto v.

  • Parameters

    Returns Vec3

  • Parameters

    • x: Vector3

    Returns Vec3

  • Parameters

    • x: Direction

    Returns Vec3

  • Parameters

    • x: number[]

    Returns Vec3

  • Computes the reflection of the current vector against a normal vector. Useful for simulating light reflections or bouncing objects.

    Parameters

    • x: number
    • y: number
    • z: number

    Returns Vec3

    A new vector representing the reflection of the current vector.

  • Parameters

    Returns Vec3

  • Parameters

    • x: Vector3

    Returns Vec3

  • Parameters

    • x: Direction

    Returns Vec3

  • Parameters

    • x: number[]

    Returns Vec3

  • Rotates the current normalized vector by a given angle around a given axis.

    Parameters

    • axis: Vector3

      The axis of rotation.

    • angle: number

      The angle of rotation in degrees.

    Returns Vec3

    The rotated vector.

  • Sets the X component of the vector.

    Parameters

    • value: number

      The new X value.

    Returns Vec3

    The updated vector with the new X value.

  • Sets the Y component of the vector.

    Parameters

    • value: number

      The new Y value.

    Returns Vec3

    The updated vector with the new Y value.

  • Sets the Z component of the vector.

    Parameters

    • value: number

      The new Z value.

    Returns Vec3

    The updated vector with the new Z value.

  • Computes the spherical linear interpolation between the current vector and another vector.

    Parameters

    • v: Vector3

      The other vector.

    • t: number

      The interpolation factor (0 <= t <= 1).

    Returns Vec3

    A new vector after performing the slerp operation.

  • Subtracts another vector from the current vector.

    Parameters

    • x: number
    • y: number
    • z: number

    Returns Vec3

    The updated vector after subtraction.

  • Parameters

    Returns Vec3

  • Parameters

    • x: Vector3

    Returns Vec3

  • Parameters

    • x: Direction

    Returns Vec3

  • Parameters

    • x: number[]

    Returns Vec3

  • Converts the vector to an array containing the X, Y, and Z components of the vector.

    Returns number[]

    An array containing the X, Y, and Z components of the vector.

  • Converts the vector to a direction. If the vector is not a unit vector, then it will be normalized and rounded to the nearest direction.

    Returns Direction

  • Returns string

  • Creates a new vector from the given values.

    Parameters

    • x: number
    • y: number
    • z: number

    Returns Vec3

  • Parameters

    Returns Vec3

  • Parameters

    • x: Vector3

    Returns Vec3

  • Parameters

    • x: Direction

    Returns Vec3

  • Parameters

    • x: number[]

    Returns Vec3

  • Creates a new direction vector from yaw and pitch values.

    Parameters

    • yaw: number

      The yaw value in degrees.

    • pitch: number

      The pitch value in degrees.

    Returns Vec3

    A new vector representing the direction.