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(b: Vector | [x: number, y: number, z: number]): Vector
• 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

• distance(b: Vector | [x: number, y: number, z: number]): number
• Compute the distance to another vector

#### Parameters

• ##### b: Vector | [x: number, y: number, z: number]

Vector to compute the distance to

### divide

• Divide by a number

#### Parameters

• ##### b: number

Number to divide the vector by

### dot

• dot(b: Vector | [x: number, y: number, z: number]): number
• Compute the dot product

#### Parameters

• ##### b: Vector | [x: number, y: number, z: number]

Vector to compute the dot product with

### equals

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

#### Parameters

• ##### b: Vector | [x: number, y: number, z: number]

Vector to compare to

• ##### errorTolerance: number

Maximum total difference

### findClosestPointOnLine

• findClosestPointOnLine(lineOrigin: Vector | [x: number, y: number, z: number], lineDirection: Vector | [x: number, y: number, z: number]): Vector
• Find the closest point on an infinite line

#### Parameters

• ##### lineOrigin: Vector | [x: number, y: number, z: number]

Point of reference on the line

• ##### lineDirection: Vector | [x: number, y: number, z: number]

Direction of the line

### findClosestPointOnSegment

• findClosestPointOnSegment(segmentStart: Vector | [x: number, y: number, z: number], segmentEnd: Vector | [x: number, y: number, z: number]): Vector
• Find the closest point to this vector on a line segment

#### Parameters

• ##### segmentStart: Vector | [x: number, y: number, z: number]

Start of the segment

• ##### segmentEnd: Vector | [x: number, y: number, z: number]

End of the segment

### findLookAtRotation

• findLookAtRotation(target: Vector | [x: number, y: number, z: number]): Rotator
• Find a rotation for an object at this location to point at a target location

#### Parameters

• ##### target: Vector | [x: number, y: number, z: number]

Target location to point at

### getDistanceToLine

• getDistanceToLine(lineOrigin: Vector | [x: number, y: number, z: number], lineDirection: Vector | [x: number, y: number, z: number]): number
• Find the distance to the closest point on an infinite line

#### Parameters

• ##### lineOrigin: Vector | [x: number, y: number, z: number]

Point of reference on the line

• ##### lineDirection: Vector | [x: number, y: number, z: number]

Direction of the line

### getDistanceToSegment

• getDistanceToSegment(segmentStart: Vector | [x: number, y: number, z: number], segmentEnd: Vector | [x: number, y: number, z: number]): number
• Find the distance to the closest point on a line segment

#### Parameters

• ##### segmentStart: Vector | [x: number, y: number, z: number]

Start of the segment

• ##### segmentEnd: Vector | [x: number, y: number, z: number]

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

• getReflectionVector(surfaceNormal: Vector | [x: number, y: number, z: number]): Vector
• Returns this vector reflected across the given surface normal

#### Parameters

• ##### surfaceNormal: Vector | [x: number, y: number, z: number]

A normal of the surface to reflect on

### isInBox

• isInBox(boxOrigin: Vector | [x: number, y: number, z: number], boxExtent: Vector | [x: number, y: number, z: number]): boolean
• Determines whether this vector is in a given box. Includes points on the box.

#### Parameters

• ##### boxOrigin: Vector | [x: number, y: number, z: number]

Origin of the box

• ##### boxExtent: Vector | [x: number, y: number, z: number]

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 (f*x, f*y, f*z)

### negate

• Return negated vector

### rotateAngleAxis

• rotateAngleAxis(angleDeg: number, axis: Vector | [x: number, y: number, z: number]): Vector
• Return result of rotating this vector around an axis

#### Parameters

• ##### angleDeg: number

Angle to rotate in degrees

• ##### axis: Vector | [x: number, y: number, z: number]

Axis to rotate around

### subtract

• subtract(b: Vector | [x: number, y: number, z: number]): Vector
• Subtract another vector and return the result

#### Parameters

• ##### b: Vector | [x: number, y: number, z: number]

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 | [x: number, y: number, z: number], target: Vector | [x: number, y: number, z: number], deltaTime: number, interpSpeed: number): Vector
• Smoothly interpolate towards a varying target vector

#### Parameters

• ##### current: Vector | [x: number, y: number, z: number]

Current vector

• ##### target: Vector | [x: number, y: number, z: number]

Target vector

• ##### deltaTime: number

Time since last tick

• ##### interpSpeed: number

Interpolation speed

### Static interpolateToConstant

• interpolateToConstant(current: Vector | [x: number, y: number, z: number], target: Vector | [x: number, y: number, z: number], deltaTime: number, interpSpeed: number): Vector
• Smoothly interpolate towards a varying target vector at a constant rate

#### Parameters

• ##### current: Vector | [x: number, y: number, z: number]

Current vector

• ##### target: Vector | [x: number, y: number, z: number]

Target vector

• ##### deltaTime: number

Time since last tick

• ##### interpSpeed: number

Interpolation speed

### Static lerp

• lerp(a: Vector | [x: number, y: number, z: number], b: Vector | [x: number, y: number, z: number], alpha: number): Vector
• Linearly interpolate between a and b based on alpha

#### Parameters

• ##### a: Vector | [x: number, y: number, z: number]

First vector

• ##### b: Vector | [x: number, y: number, z: number]

Second vector

• ##### alpha: number

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

### Static randomPointInBoundingBox

• randomPointInBoundingBox(origin: Vector | [x: number, y: number, z: number], boxExtent: Vector | [x: number, y: number, z: number]): Vector
• Return a random point within the specified bounding box

#### Parameters

• ##### origin: Vector | [x: number, y: number, z: number]

Origin of the box

• ##### boxExtent: Vector | [x: number, y: number, z: number]

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

### Static randomUnitVector

• Return a random vector with a length of 1