Represents a 3D vector with x, y, and z components.

Hierarchy

  • Vector3

Constructors

  • Creates a new Vector3 instance.

    Parameters

    • x: number = 0

      The x component of the vector. Default is 0.

    • y: number = 0

      The y component of the vector. Default is 0.

    • z: number = 0

      The z component of the vector. Default is 0.

    Returns Vector3

Properties

x: number

The x component of the vector.

y: number

The y component of the vector.

z: number

The z component of the vector.

Methods

  • Adds the given vector to this vector and returns the result as a new Vector3 instance.

    Parameters

    Returns Vector3

    A new Vector3 instance representing the sum of this vector and the given vector.

  • Subtracts the given vector from this vector and returns the result as a new Vector3 instance.

    Parameters

    • rhs: Vector3

      The vector to subtract.

    Returns Vector3

    A new Vector3 instance representing the difference between this vector and the given vector.

  • Multiplies this vector by the given scalar and returns the result as a new Vector3 instance.

    Parameters

    • rhs: number

      The scalar to multiply by.

    Returns Vector3

    A new Vector3 instance representing the product of this vector and the given scalar.

  • Divides this vector by the given scalar and returns the result as a new Vector3 instance.

    Parameters

    • rhs: number

      The scalar to divide by.

    Returns Vector3

    A new Vector3 instance representing the quotient of this vector and the given scalar.

  • Returns the negation of this vector as a new Vector3 instance.

    Returns Vector3

    A new Vector3 instance representing the negation of this vector.

  • Returns the dot product of this vector and the given vector.

    Parameters

    • rhs: Vector3

      The vector to compute the dot product with.

    Returns number

    The dot product of this vector and the given vector.

  • Returns the cross product of this vector and the given vector as a new Vector3 instance.

    Parameters

    • rhs: Vector3

      The vector to compute the cross product with.

    Returns Vector3

    A new Vector3 instance representing the cross product of this vector and the given vector.

  • Returns a string representation of this vector.

    Returns string

    A string representation of this vector.

  • Returns true if this vector is equal to the given vector, false otherwise.

    Parameters

    • rhs: Vector3

      The vector to compare with.

    Returns boolean

    True if this vector is equal to the given vector, false otherwise.

  • Returns the squared distance between this vector and the given vector.

    Parameters

    • other: Vector3

      The vector to compute the distance to.

    Returns number

    The squared distance between this vector and the given vector.

  • Returns the distance between this vector and the given vector.

    Parameters

    • other: Vector3

      The vector to compute the distance to.

    Returns number

    The distance between this vector and the given vector.

  • Returns the squared length of this vector.

    Returns number

    The squared length of this vector.

  • Returns the length of this vector.

    Returns number

    The length of this vector.

  • Returns a new normalized Vector3 instance representing this vector.

    Returns Vector3

    A new normalized Vector3 instance representing this vector.

  • Returns a tuple containing a new normalized Vector3 instance representing this vector and its length.

    Returns [Vector3, number]

    A tuple containing a new normalized Vector3 instance representing this vector and its length.

  • Returns an array containing the x, y, and z components of this vector.

    Returns [number, number, number]

    An array containing the x, y, and z components of this vector.

  • Returns true if this object is an instance of Vector3, false otherwise.

    Returns boolean

    True if this object is an instance of Vector3, false otherwise.

  • Returns a new Vector3 instance with the given polar coordinates.

    Parameters

    • theta: number

      The angle in radians.

    • radius: number = 1

      The radius. Default is 1.

    Returns Vector3

    A new Vector3 instance with the given polar coordinates.

  • Private

    Divides this vector by the given scalar and returns the result as a new Vector3 instance.

    Parameters

    • scalar: number

      The scalar to divide by.

    Returns Vector3

    A new Vector3 instance representing the quotient of this vector and the given scalar.