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

constructor

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

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

    Returns Vector3

Properties

length

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

normalized: Vector3

Returns a copy of this vector with length 1.

sqrLength

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

x: number

X component of this vector.

y

y: number

Y component of this vector.

z

z: number

Z component of this vector.

Methods

add

  • Adds this vector and other by their corresponding components.

    Parameters

    Returns Vector3

    new vector of the combined result.

angle

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

    Parameters

    Returns number

    angle in radians.

cross

  • 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.

dist

  • 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.

div

  • Divides all components of this vector by divisor d.

    Parameters

    • d: number

    Returns Vector3

    new vector of the divided result.

dot

  • 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.

equals

  • Returns true if this vector equals v.

    Parameters

    • v: Vector3

      vector to compare this vector against.

    Returns boolean

limitLength

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

    Parameters

    • l: number

    Returns Vector3

    limited length vector.

max

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

    Parameters

    Returns Vector3

min

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

    Parameters

    Returns Vector3

mult

  • Multiplies each component of this by a number m.

    Parameters

    • m: number

      multiplier.

    Returns Vector3

    new vector of the multiplied result.

normalize

  • Returns a copy of this vector with length 1.

    deprecated

    Returns Vector3

project

  • Projects this vector onto other.

    Parameters

    Returns Vector3

    vector projection.

projectOnPlane

  • 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

sub

  • Subtracts each component of other from this vector.

    Parameters

    Returns Vector3

    new vector of the subtracted result

toArray

  • toArray(): Array<number>
  • Returns Array<number>

    array representation of this vector.

Static add

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

    Parameters

    Returns Vector3

    new vector of combined result

Static angle

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

    Parameters

    Returns number

    angle in radians.

Static cross

  • 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.

Static dist

  • 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.

Static distance2

  • Returns the squared distance between vector a and vector b

    Parameters

    Returns number

    squared distance between vectors.

Static div

  • Divides all components of vector v by divisor d.

    Parameters

    Returns Vector3

    new vector of the divided result.

Static dot

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

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

    Parameters

    Returns number

    dot product.

Static equals

  • Returns true if vector a equals vector b.

    Parameters

    Returns boolean

Static max

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

    Parameters

    Returns Vector3

Static min

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

    Parameters

    Returns Vector3

Static mult

  • 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.

Static norm2

  • 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

Static project

  • Projects vector a onto vector b.

    Parameters

    Returns Vector3

    vector projection

Static projectOnPlane

  • 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.

Static sub

  • Subtracts each component of vector b from a.

    Parameters

    Returns Vector3

    new vector of the subtraction result.

Generated using TypeDoc