Options
All
• Public
• Public/Protected
• All

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

• Vector3

## Constructors

### constructor

• new Vector3(x: number, y: number, z: number): 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

• Adds this vector and `other` by their corresponding components.

#### Returns Vector3

new vector of the combined result.

### angle

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

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

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

#### Returns number

distance between vectors.

### div

• Divides all components of this vector by divisor `d`.

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

dot product.

### equals

• Returns `true` if this vector equals `v`.

#### Parameters

• ##### v: Vector3

vector to compare this vector against.

### limitLength

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

#### Returns Vector3

limited length vector.

### max

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

### min

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

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

### project

• Projects this vector onto `other`.

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

#### Returns Vector3

new vector of the subtracted result

### toArray

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

array representation of this vector.

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

#### Returns Vector3

new vector of combined result

### Static angle

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

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

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

#### Returns number

distance between vectors.

### Static distance2

• Returns the squared distance between vector `a` and vector `b`

#### Returns number

squared distance between vectors.

### Static div

• Divides all components of vector `v` by divisor `d`.

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

dot product.

### Static equals

• Returns `true` if vector `a` equals vector `b`.

#### Parameters

• ##### a: Vector3

vector to compare.

• ##### b: Vector3

vector to compare.

### Static max

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

### Static min

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

### Static mult

• Multiplies each component of vector `v` by `m`.

#### Parameters

• ##### v: Vector3

vector components to multiply.

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

#### Returns number

length of `v`

### Static project

• Projects vector `a` onto vector `b`.

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

#### Returns Vector3

new vector of the subtraction result.

Generated using TypeDoc