Module gamejs/math/vectors

Functions


add (a, b)

adds vectors [a0, a1] - [a0, a1]

Parameters

Array a vector
Array b vector

Returns

Array vector

angle (vector, vector)

calculate angle between vectors

Parameters

Array vector [v0, v1]
Array vector [v0, v1]

Returns

Number angle between v1 and v2 in radians

centroid (first, second, ...)

Parameters

Array first point
Array second point
Array ...

Returns

the center of multipled 2d points

distance (origin, target)

Parameters

Array origin point [b0, b1]
Array target point [b0, b1]

Returns

Number distance between two points

divide (a, s)

Parameters

Array a vector
Number s

dot (vector, vector)

calculate vector dot product

Parameters

Array vector [v0, v1]
Array vector [v0, v1]

Returns

Number dot product of v1 and v2

len (vector)

Parameters

Array vector [v0, v1]

Returns

Number length of vector

multiply (vector, vector)

multiply vector with scalar or other vector

Parameters

Array vector [v0, v1]
Number|Array vector or number

Returns

Number|Array result

rotate (vector, angle)

rotate vector

Parameters

Array vector [v0, v1]
Number angle to rotate vector by, radians. can be negative

Returns

Array rotated vector [v0, v1]

subtract (a, b)

subtracts vectors [a0, a1] - [a0, a1]

Parameters

Array a
Array b

Returns

Array vector

truncate (v, maxLength)

Parameters

v
maxLength

Returns

Array vector with max length as specified.

unit (vector)

normalize vector to unit vector

Parameters

Array vector [v0, v1]

Returns

Array unit vector [v0, v1]