vector_functions
v1.0.2
Published
A set of functions to manipulate vectors in javascript ## Functions
Downloads
7
Readme
vector_functions.js
A set of functions to manipulate vectors in javascript
Functions
add(vector)
this function can take multiple vectors and add them
Kind: global function
| Param | Type | Description | | --- | --- | --- | | vector | Array | This is an array of components of a vector |
Example
add([5, 15], [15, 5])
Example
add([5, 5], [10, 10], [5, 5])
sub(Vector)
This function subtracts all the given vectors
Kind: global function
| Param | Type | Description | | --- | --- | --- | | Vector | Array | takes multiple vectors and subtracts them |
mult(vector, scalar)
This function multiplies the vector given by the scalar give
Kind: global function
| Param | Type | Description | | --- | --- | --- | | vector | Array | This is an array of components of a vector | | scalar | Number | This is a number |
inverse(vector)
This function returns the inverse of the vector
Kind: global function
| Param | Type | Description | | --- | --- | --- | | vector | array | This is an array of components of a vector |
normalize(vector)
This function normalise the vector
Kind: global function
| Param | Type | Description | | --- | --- | --- | | vector | array | This is an array of components of a vector |
distance(vector1, vector2)
Returns the magnitude of the distance between the two vectors given
Kind: global function
| Param | Type | Description | | --- | --- | --- | | vector1 | array | This is an array of components of a vector | | vector2 | array | This is an array of components of a vector |
copy(vector)
Returns a copy of the given vector
Kind: global function
| Param | Type | Description | | --- | --- | --- | | vector | array | This is an array of components of a vector |
limit(vector, scalar)
Limits the magnitud of the given vector
Kind: global function
| Param | Type | Description | | --- | --- | --- | | vector | array | This is an array of components of a vector | | scalar | array | This is the maximun length of the vector |
dot(vector1, vector2)
This function returns the dot product of the two vectors given
Kind: global function
| Param | Type | Description | | --- | --- | --- | | vector1 | array | This is an array of components of a vector | | vector2 | array | This is an array of components of a vector |
mag(vector)
This functions returns the margnitud of the given vector
Kind: global function
| Param | Type | Description | | --- | --- | --- | | vector | array | This is an array of components of a vector |
moveTowards(start, end, speed, stop)
smaller than the stop parameter.ve if the magnitude of the distance is
Kind: global function
| Param | Type | Default | Description | | --- | --- | --- | --- | | start | array | | This is an array of components of a vector | | end | array | | This is an array of components of a vector | | speed | number | 1 | This is the speed in wich the first vector will move towards the second | | stop | number | 1 | This is the distance in wich the start vector will not move to the end vector |
angleBetween(vector1, vector2)
Returns the angle between 2 vectors
Kind: global function
| Param | Type | Description | | --- | --- | --- | | vector1 | array | This is an array of components of a vector | | vector2 | array | This is an array of components of a vector |
setMag(vector, scalar)
Sets the magnitud of the vector to the length of the scalar given
Kind: global function
| Param | Type | Description | | --- | --- | --- | | vector | array | This is an array of components of a vector | | scalar | number | This will be the length of the vector |
toDegree(radian)
Converts a number from radian to degree
Kind: global function
| Param | Type | Description | | --- | --- | --- | | radian | number | This number represents the radian that you want to convert |
toRadian(degree)
Converts a number from degree to radian
Kind: global function
| Param | Type | Description | | --- | --- | --- | | degree | number | This number represents the degree that you want to convert |
cross3d(vector1, vector2)
Returns the cross product of 2 vectors with 3 components
Kind: global function
| Param | Type | Description | | --- | --- | --- | | vector1 | array | This is an array of components of a vector | | vector2 | array | This is an array of components of a vector |
cross2d(vector1, vector2)
Returns the cross product of 2 vectors with 2 components
Kind: global function
| Param | Type | Description | | --- | --- | --- | | vector1 | array | This is an array of components of a vector | | vector2 | array | This is an array of components of a vector |
angle(vector)
Returns the angle of the vector
Kind: global function
| Param | Type | Description | | --- | --- | --- | | vector | array | This is an array of components of a vector |
angleMagnitude(direction, magnitud)
Creates a vector from a magnitud and a direction
Kind: global function
| Param | Type | Description | | --- | --- | --- | | direction | number | This is the direction of the vector that will be created | | magnitud | number | This is the magnitud of the vector that will be created |
linearIntersect(vector, angle)
Sets the angle of the given vector to the given angle
Kind: global function
| Param | Type | Description | | --- | --- | --- | | vector | array | This is the vector that will be changed | | angle | number | This will be the angle of the given vector in radians |
addAngle(vector, angle, piv)
Adds the angle of the given vector to the given angle
Kind: global function
| Param | Type | Description | | --- | --- | --- | | vector | array | This is the vector that will be changed | | angle | number | This will be the angle that will be added to the given vector in radians | | piv | array | This is the center of rotation |
setAngle(vector, angle)
Sets the angle of the given vector to the given angle
Kind: global function
| Param | Type | Description | | --- | --- | --- | | vector | array | This is the vector that will be changed | | angle | number | This will be the angle of the given vector in radians |