Skip to main content

Vector3

A 3D vector.

Implements

Index

Constructors

constructor

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

    • x: number

      X component of the Vector

    • y: number

      Y component of the Vector

    • z: number

      Z component of the Vector

    Returns Vector3

Properties

publicstaticEQUALS_EPSILON

EQUALS_EPSILON: number = 0.001

Get or set the vector equals epsilon, by default 0.001 meaning vectors within that tolerance on x, y, or z will be considered equal.

Accessors

publicmagnitude

  • get magnitude(): number
  • set magnitude(newMagnitude: number): void
  • The magnitude (length) of the Vector


    Returns number

  • Parameters

    • newMagnitude: number

    Returns void

publicx

  • get x(): number
  • set x(val: number): void
  • Returns number

  • Parameters

    • val: number

    Returns void

publicy

  • get y(): number
  • set y(val: number): void
  • Returns number

  • Parameters

    • val: number

    Returns void

publicz

  • get z(): number
  • set z(val: number): void
  • Returns number

  • Parameters

    • val: number

    Returns void

publicstaticBack

  • A unit vector pointing backward/in (0, 0, -1)


    Returns Vector3

publicstaticDown

  • A unit vector pointing down (0, 1, 0)


    Returns Vector3

publicstaticForward

  • A unit vector pointing forward/out (0, 0, 1)


    Returns Vector3

publicstaticLeft

  • A unit vector pointing left (-1, 0, 0)


    Returns Vector3

publicstaticOne

publicstaticRight

  • A unit vector pointing right (1, 0, 0)


    Returns Vector3

publicstaticUp

  • A unit vector pointing up (0, -1, 0)


    Returns Vector3

publicstaticZero

Methods

publicadd

publicaddEqual

  • Adds one vector to this one modifying the original


    Parameters

    Returns Vector3

publicaverage

  • Returns the average (midpoint) between the current point and the specified point


    Parameters

    Returns Vector3

publicclampMagnitude

  • clampMagnitude(magnitude: number): Vector3
  • Clamps the current vector's magnitude mutating it


    Parameters

    • magnitude: number

    Returns Vector3

publicclone

  • Creates new vector that has the same values as the previous.


    Parameters

    Returns Vector3

publiccross

publicdistance

  • The distance to another vector. If no other Vector is specified, this will return magnitude.


    Parameters

    Returns number

publicdot

  • Performs a dot product with another vector


    Parameters

    Returns number

publicequals

  • equals(vector: Vector3, tolerance?: number): boolean
  • Compares this vector against another and tests for equality


    Parameters

    • vector: Vector3
    • tolerance: number = Vector3.EQUALS_EPSILON

    Returns boolean

publiclerp

  • Linearly interpolates between current vector and target vector.


    Parameters

    Returns Vector3

publicnegate

  • Negate the current vector


    Returns Vector3

publicnormalize

  • Normalizes a non-zero vector to have a magnitude of 1. Zero vectors return a new zero vector.


    Returns Vector3

publicscale

  • Scales a vector by a factor or component-wise vector


    Parameters

    Returns Vector3

publicscaleEqual

  • Scales this vector by a factor and modifies the original


    Parameters

    • size: number

    Returns Vector3

publicsetTo

  • setTo(x: number, y: number, z: number): void
  • Sets the x, y, and z components at once, THIS MUTATES the current vector.


    Parameters

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

    Returns void

publicsquareDistance

  • squareDistance(v?: Vector3): number
  • Parameters

    Returns number

publicsub

publicsubEqual

  • Subtracts a vector from this one modifying the original


    Parameters

    Returns Vector3

publictoArray

  • toArray(dest?: number[], offset?: number): number[]
  • toArray(dest: Float32Array, offset?: number): Float32Array
  • Copies components out into an array or Float32Array


    Parameters

    • optionaldest: number[]
    • optionaloffset: number

    Returns number[]

publictoFloat32Array

  • toFloat32Array(): Float32Array
  • Converts to a Float32Array suitable for WebGL uniforms


    Returns Float32Array

publictoString

  • toString(fixed?: number): string
  • Returns a string representation of the vector.


    Parameters

    • optionalfixed: number

    Returns string

publicstaticdistance

  • Calculates distance between two Vectors


    Parameters

    Returns number

publicstaticfromArray

  • fromArray(array: number[] | Float32Array<ArrayBufferLike>, offset?: number): Vector3
  • Creates a Vector3 from an array [x, y, z]


    Parameters

    • array: number[] | Float32Array<ArrayBufferLike>
    • offset: number = 0

    Returns Vector3

publicstaticisValid

  • Checks if vector is not null, undefined, or if any of its components are NaN or Infinity.


    Parameters

    Returns boolean

publicstaticmax

publicstaticmin