Dev » Lua API » vector4
← Back to all classes

vector4

Math 4 Properties 4 Methods

vector4

The vector4 class represents 4D floating point coordinates (X, Y, Z, W). Supports vector addition, subtraction, scalar multiplication, normalization, and dot products.

Overview

Properties (4)

Property Type Summary
w number The W component.
x number The X component.
y number The Y component.
z number The Z component.

Methods (4)

Method Signature Returns Summary
vector4:dot(other) number Calculates the dot product with another 4D vector.
vector4:length() number Calculates the length of the 4D vector.
vector4.new(x, y, z, w) vector4 Constructs a new 4D vector.
vector4:normalized() vector4 Returns a normalized unit vector.

Detailed Reference

# w PROPERTY
vector4.w
The W component.
Parameters
None
Returns
number

The W coordinate component.

Description

Reads or writes the W coordinate component.

# x PROPERTY
vector4.x
The X component.
Parameters
None
Returns
number

The X coordinate component.

Description

Reads or writes the X coordinate component.

# y PROPERTY
vector4.y
The Y component.
Parameters
None
Returns
number

The Y coordinate component.

Description

Reads or writes the Y coordinate component.

# z PROPERTY
vector4.z
The Z component.
Parameters
None
Returns
number

The Z coordinate component.

Description

Reads or writes the Z coordinate component.

# dot METHOD
vector4:dot(other)
Calculates the dot product with another 4D vector.
Parameters
ParameterTypeDefaultDescription
othervector4

The other 4D vector.

Returns
number

Dot product value.

Description

Computes x1 x2 + y1 y2 + z1 z2 + w1 w2.

# length METHOD
vector4:length()
Calculates the length of the 4D vector.
Parameters
None
Returns
number

Euclidean magnitude.

Description

Calculates sqrt(x^2 + y^2 + z^2 + w^2).

# new METHOD
vector4.new(x, y, z, w)
Constructs a new 4D vector.
Parameters
ParameterTypeDefaultDescription
xnumber

The X coordinate.

ynumber

The Y coordinate.

znumber

The Z coordinate.

wnumber

The W coordinate.

Returns
vector4

Newly constructed 4D vector.

Description

Creates a 4D vector with four components.

# normalized METHOD
vector4:normalized()
Returns a normalized unit vector.
Parameters
None
Returns
vector4

Unit vector with length 1.0.

Description

Scales the 4D vector to length 1.0.