Options
All
  • Public
  • Public/Protected
  • All
Menu

A point or direction in 3d space

Hierarchy

  • Vector

Implements

  • Iterable<number>

Index

Constructors

constructor

  • new Vector(x: number, y: number, z: number): Vector
  • Make a vector {x, y, z} from coordinate values

    Parameters

    • x: number

      Y coordinate

    • y: number
    • z: number

    Returns Vector

Properties

0

0: number

X coordinate

1

1: number

Y coordinate

2

2: number

Z coordinate

x

x: number

X coordinate

y

y: number

Y coordinate

z

z: number

Z coordinate

Methods

[Symbol.iterator]

  • [Symbol.iterator](): Iterator<number>

add

clampVectorMagnitude

  • clampVectorMagnitude(min: number, max: number): Vector
  • Clamp the vector length between a min and max length

    Parameters

    • min: number

      Minimum length of resulting vector

    • max: number

      Maximum length of resulting vector

    Returns Vector

clone

distance

  • Compute the distance to another vector

    Parameters

    • b: Vector

      Vector to compute the distance to

    Returns number

divide

  • Divide by a number

    Parameters

    • b: number

      Number to divide the vector by

    Returns Vector

dot

  • Compute the dot product

    Parameters

    • b: Vector

      Vector to compute the dot product with

    Returns number

equals

  • equals(b: Vector, errorTolerance: number): boolean
  • Return true if this vector is equal to vector b (a == b) within a specified error tolerance

    Parameters

    • b: Vector

      Vector to compare to

    • errorTolerance: number

      Maximum total difference

    Returns boolean

findClosestPointOnLine

  • Find the closest point on an infinite line

    Parameters

    • lineOrigin: Vector

      Point of reference on the line

    • lineDirection: Vector

      Direction of the line

    Returns Vector

findClosestPointOnSegment

  • Find the closest point to this vector on a line segment

    Parameters

    • segmentStart: Vector

      Start of the segment

    • segmentEnd: Vector

      End of the segment

    Returns Vector

findLookAtRotation

  • Find a rotation for an object at this location to point at a target location

    Parameters

    • target: Vector

      Target location to point at

    Returns Rotator

getDistanceToLine

  • getDistanceToLine(lineOrigin: Vector, lineDirection: Vector): number
  • Find the distance to the closest point on an infinite line

    Parameters

    • lineOrigin: Vector

      Point of reference on the line

    • lineDirection: Vector

      Direction of the line

    Returns number

getDistanceToSegment

  • getDistanceToSegment(segmentStart: Vector, segmentEnd: Vector): number
  • Find the distance to the closest point on a line segment

    Parameters

    • segmentStart: Vector

      Start of the segment

    • segmentEnd: Vector

      End of the segment

    Returns number

getMaxElement

  • getMaxElement(): number
  • Find the maximum element (x, y, or y)

    Returns number

getMinElement

  • getMinElement(): number
  • Find the minimum element (x, y, or z)

    Returns number

getReflectionVector

  • Returns this vector reflected across the given surface normal

    Parameters

    • surfaceNormal: Vector

      A normal of the surface to reflect on

    Returns Vector

isInBox

  • Determines whether this vector is in a given box. Includes points on the box.

    Parameters

    • boxOrigin: Vector

      Origin of the box

    • boxExtent: Vector

      Extent of the box (distance in each axis from box origin)

    Returns boolean

magnitude

  • magnitude(): number
  • Return the length of this vector

    Returns number

magnitudeSquared

  • magnitudeSquared(): number
  • Return the squared length of this vector

    Returns number

multiply

  • Multipley element-wise (fx, fy, f*z)

    Parameters

    • f: number

    Returns Vector

negate

rotateAngleAxis

  • Return result of rotating this vector around an axis

    Parameters

    • angleDeg: number

      Angle to rotate in degrees

    • axis: Vector

      Axis to rotate around

    Returns Vector

subtract

toColor

toRotator

  • Create a rotator that orients X along the direction given by this vector

    Returns Rotator

toString

  • toString(): string
  • Convert to a string in the form 'X= Y= Z='

    Returns string

unit

Static getVectorArrayAverage

  • Find the average of an array of vectors

    Parameters

    • vectors: Vector[]

      An array of vectors to average

    Returns Vector

Static interpolateTo

  • interpolateTo(current: Vector, target: Vector, deltaTime: number, interpSpeed: number): Vector
  • Smoothly interpolate towards a varying target vector

    Parameters

    • current: Vector

      Current vector

    • target: Vector

      Target vector

    • deltaTime: number

      Time since last tick

    • interpSpeed: number

      Interpolation speed

    Returns Vector

Static interpolateToConstant

  • interpolateToConstant(current: Vector, target: Vector, deltaTime: number, interpSpeed: number): Vector
  • Smoothly interpolate towards a varying target vector at a constant rate

    Parameters

    • current: Vector

      Current vector

    • target: Vector

      Target vector

    • deltaTime: number

      Time since last tick

    • interpSpeed: number

      Interpolation speed

    Returns Vector

Static lerp

  • Linearly interpolate between a and b based on alpha

    Parameters

    • a: Vector

      First vector

    • b: Vector

      Second vector

    • alpha: number

      Result is 100% of a when alpha=0 and 100% of b when alpha=1

    Returns Vector

Static randomPointInBoundingBox

  • Return a random point within the specified bounding box

    Parameters

    • origin: Vector

      Origin of the box

    • boxExtent: Vector

      Extent of the box (distance in each axis from box origin)

    Returns Vector

Static randomUnitVector