math# Vector

Represents a 3D vector.

Constructor

new Vector(parametersopt)

Creates a new Vector instance.

Parameters:
NameTypeAttributesDescription
parametersObject<optional>

The parameters for the vector.

Properties
NameTypeAttributesDefaultDescription
xnumber<optional>
0

The X component of the vector.

ynumber<optional>
0

The Y component of the vector.

znumber<optional>
0

The Z component of the vector.

Members

NEGATIVE_X

The NEGATIVE_X vector is a unit vector pointing in the negative x direction.

NEGATIVE_Y

The NEGATIVE_Y vector is a unit vector pointing in the negative y direction.

NEGATIVE_Z

The NEGATIVE_Z vector is a unit vector pointing in the negative z direction.

X

The X vector is a unit vector pointing in the positive x direction.

Y

The Y vector is a unit vector pointing in the positive y direction.

Z

The Z vector is a unit vector pointing in the positive z direction.

ZERO

The ZERO vector is an empty vector.

length

Gets the length (magnitude) of this vector.

x

Gets the X component of this vector.

x

Sets the X component of this vector.

y

Gets the Y component of this vector.

y

Sets the Y component of this vector.

z

Gets the Z component of this vector.

z

Sets the Z component of this vector.

Methods

add(other) → {Vector}

Adds another vector to this vector.

Parameters:
NameTypeDescription
otherVector

The vector to add.

Returns:

A new Vector representing the result.

Type: 
Vector

angle(other) → {number}

Computes the angle between this vector and another vector.

Parameters:
NameTypeDescription
otherVector

The other vector.

Returns:

The angle between the vectors in radians.

Type: 
number

cross(other) → {Vector}

Computes the cross product of this vector with another vector.

Parameters:
NameTypeDescription
otherVector

The other vector.

Returns:

A new Vector representing the result.

Type: 
Vector

distance(other) → {number}

Computes the distance between this vector and another vector.

Parameters:
NameTypeDescription
otherVector

The other vector.

Returns:

The distance between the vectors.

Type: 
number

divide(scalar) → {Vector}

Divides this vector by a scalar.

Parameters:
NameTypeDescription
scalarnumber

The scalar to divide by.

Returns:

A new Vector representing the result.

Type: 
Vector

dot(other) → {number}

Computes the dot product of this vector with another vector.

Parameters:
NameTypeDescription
otherVector

The other vector.

Returns:

The dot product of the two vectors.

Type: 
number

isEqual(other) → {boolean}

Checks if this vector is equal to another vector.

Parameters:
NameTypeDescription
otherVector

The other vector.

Returns:

true if the vectors are equal, false otherwise.

Type: 
boolean

isParallel(other) → {boolean}

Checks if this vector is parallel to another vector.

Parameters:
NameTypeDescription
otherVector

The other vector.

Returns:

true if the vectors are parallel, false otherwise.

Type: 
boolean

isPerpendicular(other) → {boolean}

Checks if this vector is perpendicular (normal) to another vector.

Parameters:
NameTypeDescription
otherVector

The other vector.

Returns:

true if the vectors are perpendicular, false otherwise.

Type: 
boolean

mirror(plane) → {Vector}

Mirrors this vector across a specified plane.

Parameters:
NameTypeDescription
planePlane

The plane to mirror across.

Returns:

A new Vector representing the mirrored result.

Type: 
Vector

multiply(scalar) → {Vector}

Multiplies this vector by a scalar.

Parameters:
NameTypeDescription
scalarnumber

The scalar to multiply by.

Returns:

A new Vector representing the result.

Type: 
Vector

normalize() → {Vector}

Normalizes this vector to have a length of 1.

Returns:

A new Vector representing the result.

Type: 
Vector

rotate(parameters) → {Vector}

Rotates this vector around a specified axis by a given angle.

Parameters:
NameTypeDescription
parametersObject

Rotation parameters.

Properties
NameTypeDescription
axisAxis

The axis to rotate around.

anglenumber

The rotation angle in radians.

Returns:

A new Vector representing the result.

Type: 
Vector

scale(scalar) → {Vector}

Scales this vector by a scalar.

Parameters:
NameTypeDescription
scalarnumber

The scaling factor.

Returns:

A new Vector representing the result.

Type: 
Vector

subtract(other) → {Vector}

Subtracts another vector from this vector.

Parameters:
NameTypeDescription
otherVector

The vector to subtract.

Returns:

A new Vector representing the result.

Type: 
Vector