Options
All
• Public
• Public/Protected
• All

# Class Vector

A point or direction in 3d space

• Vector

### Implements

• Iterable<number>

## 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

0: number

X coordinate

1: number

Y coordinate

2: number

Z coordinate

x: number

X coordinate

y: number

Y coordinate

z: number

Z coordinate

## Methods

### [Symbol.iterator]

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

• Add another vector and return the result

### 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

### clone

• Return a copy of this Vector

### distance

• Compute the distance to another vector

#### Parameters

• ##### b: Vector

Vector to compute the distance to

### divide

• Divide by a number

#### Parameters

• ##### b: number

Number to divide the vector by

### dot

• Compute the dot product

#### Parameters

• ##### b: Vector

Vector to compute the dot product with

### 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

### findClosestPointOnLine

• Find the closest point on an infinite line

#### Parameters

• ##### lineOrigin: Vector

Point of reference on the line

• ##### lineDirection: Vector

Direction of the line

### 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

### findLookAtRotation

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

#### Parameters

• ##### target: Vector

Target location to point at

### 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

### 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

### getMaxElement

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

### getMinElement

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

### getReflectionVector

• Returns this vector reflected across the given surface normal

#### Parameters

• ##### surfaceNormal: Vector

A normal of the surface to reflect on

### 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)

### magnitude

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

### magnitudeSquared

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

### multiply

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

### negate

• Return negated vector

### rotateAngleAxis

• Return result of rotating this vector around an axis

#### Parameters

• ##### angleDeg: number

Angle to rotate in degrees

• ##### axis: Vector

Axis to rotate around

### subtract

• Subtract another vector and return the result

#### Parameters

• ##### b: Vector

Vector to subtract

### toColor

• Convert to a Color with r=x g=y b=z

### toRotator

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

### toString

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

### unit

• Return a unit normal version of this vector

### Static getVectorArrayAverage

• Find the average of an array of vectors

#### Parameters

• ##### vectors: Vector[]

An array of vectors to average

### 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

### 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

### 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

### 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)

### Static randomUnitVector

• Return a random vector with a length of 1