du.math.la
Module containing various linear algebra structures and methods.
Vector2
du.math.la.Vector2(coords)
Class representing an immutable 2D vector.
| arg | type | description |
|---|
| coords | Array | Vector coordinates. |
x
du.math.la.Vector2.x()
Returns the X component.
| return | description |
|---|
number | The X component of the vector. |
y
du.math.la.Vector2.y()
Returns the Y component.
| return | description |
|---|
number | The Y component of the vector. |
length
du.math.la.Vector2.length(len)
Sets or returns the length of the vector.
| arg | type | description |
|---|
| len | number | Length to set. If not specified, current length is returned. |
| return | description |
|---|
number du.math.la.Vector2 | A 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.
| arg | type | description |
|---|
| ang | number | Angle to set in radians. If not specified, current angle is returned. |
| return | description |
|---|
number du.math.la.Vector2 | A 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.
| return | description |
|---|
Array | Array containing the X and coordinates. |
map
du.math.la.Vector2.map(func)
Maps the vector using the specified function.
| arg | type | description |
|---|
| func | function | Function to call on the vector. Must accept an array of 2 elements. |
| return | description |
|---|
du.math.la.Vector2 | The mapped vector. |
add
du.math.la.Vector2.add(v)
Adds another vector to this vector and returns the result vector. This vector remains unchanged.
| arg | type | description |
|---|
| v | du.math.la.Vector2 | Vector to add to current one. |
| return | description |
|---|
du.math.la.Vector2 | The result vector. |
sub
du.math.la.Vector2.sub(v)
Subtracts another vector from this vector and returns the result vector. This vector remains unchanged.
| arg | type | description |
|---|
| v | du.math.la.Vector2 | Vector to subtract from current one. |
| return | description |
|---|
du.math.la.Vector2 | The result vector. |
multiply
du.math.la.Vector2.multiply(s)
Multiplies this vector with a scalar and returns the result vector. This vector remains unchanged.
| arg | type | description |
|---|
| s | number | Scalar to multiply current vector with. |
| return | description |
|---|
du.math.la.Vector2 | The result vector. |
Vector3
du.math.la.Vector3(coords)
Class representing a 3D vector.
| arg | type | description |
|---|
| coords | Array | Vector coordinates. |
x
du.math.la.Vector3.x()
Returns the X component.
| return | description |
|---|
number | The X component of the vector. |
y
du.math.la.Vector3.y()
Returns the Y component.
| return | description |
|---|
number | The Y component of the vector. |
z
du.math.la.Vector3.z()
Returns the Z component.
| return | description |
|---|
number | The Z component of the vector. |
length
du.math.la.Vector3.length(len)
Sets or returns the length of the vector.
| arg | type | description |
|---|
| len | number | Length to set. If not specified, current length is returned. |
| return | description |
|---|
number du.math.la.Vector3 | A 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.
| return | description |
|---|
du.math.la.LatLon | The 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.
| arg | type | description |
|---|
| v | du.math.la.Vector3 | Vector to add to current one. |
| return | description |
|---|
du.math.la.Vector3 | The result vector. |
multiply
du.math.la.Vector3.multiply(s)
Multiplies this vector with a scalar and returns the result vector. This vector remains unchanged.
| arg | type | description |
|---|
| s | number | Scalar to multiply current vector with. |
| return | description |
|---|
du.math.la.Vector3 | The result vector. |
dot
du.math.la.Vector3.dot(v)
Returns the dot product with another vector. The vector remains unchanged.
| arg | type | description |
|---|
| v | du.math.la.Vector3 | Vector to multiply this vector with. |
| return | description |
|---|
number | The dot product of the two vectors. |
cross
du.math.la.Vector3.cross(v)
Returns the cross product with another vector. The vector remains unchanged.
| arg | type | description |
|---|
| v | du.math.la.Vector3 | Vector to multiply this vector with. |
| return | description |
|---|
du.math.la.Vector3 | The result vector. |
LatLon
du.math.la.LatLon(latLon)
Class representing a latitude/longitude pair.
| arg | type | description |
|---|
| latLon | Array | Array containing latitude and longitude. |
toArray
du.math.la.LatLon.toArray()
Returns the array representation of the geolocation.
| return | description |
|---|
Array | Latitude/longitude in an array. |
toVec
du.math.la.LatLon.toVec()
Returns the Cartesian
du.math.la.Vector3 representation of the geolocation with unit radius.
| return | description |
|---|
du.math.la.Vector3 | Vector3 representation of the geolocation with unit radius. |