du.math.la

Module containing various linear algebra structures and methods.

Vector2

du.math.la.Vector2(coords)

Class representing an immutable 2D vector.
argtypedescription
coordsArrayVector coordinates.

x

du.math.la.Vector2.x()

Returns the X component.
returndescription
numberThe X component of the vector.

y

du.math.la.Vector2.y()

Returns the Y component.
returndescription
numberThe Y component of the vector.

length

du.math.la.Vector2.length(len)

Sets or returns the length of the vector.
argtypedescription
lennumberLength to set. If not specified, current length is returned.
returndescription
number du.math.la.Vector2A new vector with the specified length if length is set, current length otherwise.

angle

du.math.la.Vector2.angle(ang)

Sets or returns the angle of the vector in radians.
argtypedescription
angnumberAngle to set in radians. If not specified, current angle is returned.
returndescription
number du.math.la.Vector2A new vector with the specified angle if angle is set, current angle otherwise.

toArray

du.math.la.Vector2.toArray()

Returns the array representation of the vector.
returndescription
ArrayArray containing the X and coordinates.

map

du.math.la.Vector2.map(func)

Maps the vector using the specified function.
argtypedescription
funcfunctionFunction to call on the vector. Must accept an array of 2 elements.
returndescription
du.math.la.Vector2The mapped vector.

add

du.math.la.Vector2.add(v)

Adds another vector to this vector and returns the result vector. This vector remains unchanged.
argtypedescription
vdu.math.la.Vector2Vector to add to current one.
returndescription
du.math.la.Vector2The result vector.

sub

du.math.la.Vector2.sub(v)

Subtracts another vector from this vector and returns the result vector. This vector remains unchanged.
argtypedescription
vdu.math.la.Vector2Vector to subtract from current one.
returndescription
du.math.la.Vector2The result vector.

multiply

du.math.la.Vector2.multiply(s)

Multiplies this vector with a scalar and returns the result vector. This vector remains unchanged.
argtypedescription
snumberScalar to multiply current vector with.
returndescription
du.math.la.Vector2The result vector.

Vector3

du.math.la.Vector3(coords)

Class representing a 3D vector.
argtypedescription
coordsArrayVector coordinates.

x

du.math.la.Vector3.x()

Returns the X component.
returndescription
numberThe X component of the vector.

y

du.math.la.Vector3.y()

Returns the Y component.
returndescription
numberThe Y component of the vector.

z

du.math.la.Vector3.z()

Returns the Z component.
returndescription
numberThe Z component of the vector.

length

du.math.la.Vector3.length(len)

Sets or returns the length of the vector.
argtypedescription
lennumberLength to set. If not specified, current length is returned.
returndescription
number du.math.la.Vector3A new vector with the specified length if length is set, current length otherwise.

toLatLon

du.math.la.Vector3.toLatLon()

Returns the latitude/longitude representation of the vector.
returndescription
du.math.la.LatLonThe corresponding LatLon object.

add

du.math.la.Vector3.add(v)

Adds another vector to this vector and returns the result vector. This vector remains unchanged.
argtypedescription
vdu.math.la.Vector3Vector to add to current one.
returndescription
du.math.la.Vector3The result vector.

multiply

du.math.la.Vector3.multiply(s)

Multiplies this vector with a scalar and returns the result vector. This vector remains unchanged.
argtypedescription
snumberScalar to multiply current vector with.
returndescription
du.math.la.Vector3The result vector.

dot

du.math.la.Vector3.dot(v)

Returns the dot product with another vector. The vector remains unchanged.
argtypedescription
vdu.math.la.Vector3Vector to multiply this vector with.
returndescription
numberThe dot product of the two vectors.

cross

du.math.la.Vector3.cross(v)

Returns the cross product with another vector. The vector remains unchanged.
argtypedescription
vdu.math.la.Vector3Vector to multiply this vector with.
returndescription
du.math.la.Vector3The result vector.

LatLon

du.math.la.LatLon(latLon)

Class representing a latitude/longitude pair.
argtypedescription
latLonArrayArray containing latitude and longitude.

toArray

du.math.la.LatLon.toArray()

Returns the array representation of the geolocation.
returndescription
ArrayLatitude/longitude in an array.

toVec

du.math.la.LatLon.toVec()

Returns the Cartesian du.math.la.Vector3 representation of the geolocation with unit radius.
returndescription
du.math.la.Vector3Vector3 representation of the geolocation with unit radius.