VectorMath

A helper object for performing 2D and 3D vector math.

Summary
VectorMathA helper object for performing 2D and 3D vector math.
Preference DialogNone.
Functions
vector
distance
add
sub
mul
dot
cross
len
normalize

Preference Dialog

None.

Functions

vector

vector(x, y, z);
vector(x, y);

Constructor for creating a 2D or 3D vector.

Parameters

x(float)
y(float)
z(float) Optional.

Returns

(object) a Vector3.

distance

distacne(v1, v2);

Returns the cartesian distance between two points in space.

Parameters

v1(object) a Vector2 or Vector3.
v2(object) a Vector2 or Vector3.

Returns

(float) distance between v1 and v2.

add

add(v1, v2);

Adds two vectors component-wise.

Parameters

v1(object) a Vector2 or Vector3.
v2(object) a Vector2 or Vector3.

Returns

(object) a Vector2 or Vector3.

sub

sub(v1, v2);

Substracts v2 from v1 component-wise.

Parameters

v1(object) a Vector2 or Vector3.
v2(object) a Vector2 or Vector3.

Returns

(object) a Vector2 or Vector3.

mul

mul(scaler, v);

Multiply a scaler with a vector component-wise.

Parameters

scaler(float).
v(object) a Vector2 or Vector3.

Returns

(object) a Vector2 or Vector3.

dot

dot(v1, v2);

Returns the dot product between v1 and v2.

Parameters

v1(object) a Vector2 or Vector3.
v2(object) a Vector2 or Vector3.

Returns

(float)

cross

cross(v1, v2);

Returns the cross product between v1 and v2.

Parameters

v1(object) a Vector3.
v2(object) a Vector3.

Returns

(object) a Vector3.

len

len(v);

Returns the length of v.

Parameters

v(object) a Vector2 or Vector3.

Returns

(float)

normalize

normalize(v);

Normalize input vector so that its length is 1.

Parameters

v(object) a Vector2 or Vector3.

Returns

(object) a Vector2 or Vector3.

Close