Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Vector3

Represents 3D points and vectors.

Use this class to pass positions and directions to item transforms and perform vector operations.

Note: By default, DX engine uses Z as "up".

Hierarchy

  • Vector3

Index

Constructors

  • new Vector3(x: number, y: number, z: number): Vector3
  • Parameters

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

    Returns Vector3

Properties

length: number

Returns the length of this vector.

The length is calculated by the square root of (x * x + y * y + z * z).

returns

length of this vector.

normalized: Vector3

Returns a copy of this vector with length 1.

sqrLength: number

Returns the squared length of this vector.

If you use vector lengths to compare distances, squared lengths are more performant and preferred to use.

returns

squared length of this vector

x: number

X component of this vector.

y: number

Y component of this vector.

z: number

Z component of this vector.

one: Vector3

Shorthand for writing new Vector3(1,1,1).

zero: Vector3

Shorthand for writing new Vector3(0,0,0).

Methods

  • Adds this vector and other by their corresponding components.

    Parameters

    Returns Vector3

    new vector of the combined result.

  • Returns the angle in radians from this vector to other.

    Parameters

    Returns number

    angle in radians.

  • Calculates the cross product of this vector and other

    The cross product of two vectors results in a third vector which is perpendicular to the two input vectors. The result's magnitude is equal to the magnitudes of the two inputs multiplied together and then multiplied by the sine of the angle between the inputs. You can determine the direction of the result vector using the "left hand rule".

    Parameters

    Returns Vector3

    cross product.

  • Returns the distance between this vector and other.

    Note: a.dist(other) is the same as a.sub(b).length.

    Parameters

    Returns number

    distance between vectors.

  • Divides all components of this vector by divisor d.

    Parameters

    • d: number

    Returns Vector3

    new vector of the divided result.

  • Calculates the dot product of this vector and other.

    The dot product is a number equal to the lengths of two vectors multiplied together and then multiplied by the cosine of the angle between them.

    Parameters

    Returns number

    dot product.

  • Returns true if this vector equals v.

    Parameters

    • v: Vector3

      vector to compare this vector against.

    Returns boolean

  • Returns a copy of this vector with limited length l.

    Parameters

    • l: number

    Returns Vector3

    limited length vector.

  • Returns a new vector made from the largest components of this vector and other

    Parameters

    Returns Vector3

  • Returns a new vector made from the smallest components of this vector and other

    Parameters

    Returns Vector3

  • Multiplies each component of this by a number m.

    Parameters

    • m: number

      multiplier.

    Returns Vector3

    new vector of the multiplied result.

  • Projects this vector onto other.

    Parameters

    Returns Vector3

    vector projection.

  • Projects this vector onto a plane defined by a normal that is orthogonal to it.

    Parameters

    • normal: Vector3

      direction from the vector towards the plane.

    Returns Vector3

    location of vector on the plane

  • Subtracts each component of other from this vector.

    Parameters

    Returns Vector3

    new vector of the subtracted result

  • toArray(): number[]
  • Returns number[]

    array representation of this vector.

  • Adds vector a and vector b by their corresponding components.

    Parameters

    Returns Vector3

    new vector of combined result

  • Returns the angle in radians from this vector a to vector b.

    Parameters

    Returns number

    angle in radians.

  • Calculates the cross product of vector a and vector b.

    The cross product of two vectors results in a third vector which is perpendicular to the two input vectors. The result's length is equal to the lengths of the two inputs multiplied together and then multiplied by the sine of the angle between the inputs. You can determine the direction of the result vector using the "left hand rule".

    Parameters

    Returns Vector3

    cross product.

  • Returns the distance between vector a and vector b.

    Note: a.dist(b) is the same as a.sub(b).length.

    Parameters

    Returns number

    distance between vectors.

  • Returns the squared distance between vector a and vector b

    Parameters

    Returns number

    squared distance between vectors.

  • Divides all components of vector v by divisor d.

    Parameters

    Returns Vector3

    new vector of the divided result.

  • Calculates the dot product of vector a and vector b.

    The dot product is a number equal to the lengths of two vectors multiplied together and then multiplied by the cosine of the angle between them.

    Parameters

    Returns number

    dot product.

  • Returns true if vector a equals vector b.

    Parameters

    Returns boolean

  • Returns a vector made from the largest components of vector a and vector b.

    Parameters

    Returns Vector3

  • Returns a vector made from the smallest components of vector a and vector b.

    Parameters

    Returns Vector3

  • Multiplies each component of vector v by m.

    Parameters

    • v: Vector3

      vector components to multiply.

    • m: number

    Returns Vector3

    new vector of the multiplied result.

  • Returns the length of vector v.

    The length is made up from the square root of (x * x + y * y + z * z).

    Parameters

    Returns number

    length of v

  • Projects vector a onto vector b.

    Parameters

    Returns Vector3

    vector projection

  • Projects vector v onto a plane defined by a normal that is orthogonal to it.

    Parameters

    • v: Vector3

      position of the vector above the plane.

    • normal: Vector3

      direction from the vector towards the plane.

    Returns Vector3

    location of vector on the plane.

  • Subtracts each component of vector b from a.

    Parameters

    Returns Vector3

    new vector of the subtraction result.