1.0.2 • Published 7 years ago

vector_functions v1.0.2

Weekly downloads
2
License
ISC
Repository
github
Last release
7 years ago

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

ParamTypeDescription
vectorArrayThis 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

ParamTypeDescription
VectorArraytakes multiple vectors and subtracts them

mult(vector, scalar)

This function multiplies the vector given by the scalar give

Kind: global function

ParamTypeDescription
vectorArrayThis is an array of components of a vector
scalarNumberThis is a number

inverse(vector)

This function returns the inverse of the vector

Kind: global function

ParamTypeDescription
vectorarrayThis is an array of components of a vector

normalize(vector)

This function normalise the vector

Kind: global function

ParamTypeDescription
vectorarrayThis 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

ParamTypeDescription
vector1arrayThis is an array of components of a vector
vector2arrayThis is an array of components of a vector

copy(vector)

Returns a copy of the given vector

Kind: global function

ParamTypeDescription
vectorarrayThis is an array of components of a vector

limit(vector, scalar)

Limits the magnitud of the given vector

Kind: global function

ParamTypeDescription
vectorarrayThis is an array of components of a vector
scalararrayThis is the maximun length of the vector

dot(vector1, vector2)

This function returns the dot product of the two vectors given

Kind: global function

ParamTypeDescription
vector1arrayThis is an array of components of a vector
vector2arrayThis is an array of components of a vector

mag(vector)

This functions returns the margnitud of the given vector

Kind: global function

ParamTypeDescription
vectorarrayThis 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

ParamTypeDefaultDescription
startarrayThis is an array of components of a vector
endarrayThis is an array of components of a vector
speednumber1This is the speed in wich the first vector will move towards the second
stopnumber1This 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

ParamTypeDescription
vector1arrayThis is an array of components of a vector
vector2arrayThis 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

ParamTypeDescription
vectorarrayThis is an array of components of a vector
scalarnumberThis will be the length of the vector

toDegree(radian)

Converts a number from radian to degree

Kind: global function

ParamTypeDescription
radiannumberThis number represents the radian that you want to convert

toRadian(degree)

Converts a number from degree to radian

Kind: global function

ParamTypeDescription
degreenumberThis 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

ParamTypeDescription
vector1arrayThis is an array of components of a vector
vector2arrayThis is an array of components of a vector

cross2d(vector1, vector2)

Returns the cross product of 2 vectors with 2 components

Kind: global function

ParamTypeDescription
vector1arrayThis is an array of components of a vector
vector2arrayThis is an array of components of a vector

angle(vector)

Returns the angle of the vector

Kind: global function

ParamTypeDescription
vectorarrayThis is an array of components of a vector

angleMagnitude(direction, magnitud)

Creates a vector from a magnitud and a direction

Kind: global function

ParamTypeDescription
directionnumberThis is the direction of the vector that will be created
magnitudnumberThis 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

ParamTypeDescription
vectorarrayThis is the vector that will be changed
anglenumberThis 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

ParamTypeDescription
vectorarrayThis is the vector that will be changed
anglenumberThis will be the angle that will be added to the given vector in radians
pivarrayThis is the center of rotation

setAngle(vector, angle)

Sets the angle of the given vector to the given angle

Kind: global function

ParamTypeDescription
vectorarrayThis is the vector that will be changed
anglenumberThis will be the angle of the given vector in radians