Skip to content

luis-herasme/vectorFunctionsJs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

vector_functions.js

A set of functions to manipulate vectors in javascript

Functions

add(vector)

This function adds all the given vectors, this function can take multiple vectors and add them

sub(Vector)

This function subtracts all the given vectors

mult(vector, scalar)

This function multiplies the vector given by the scalar give

inverse(vector)

This function returns the inverse of the vector

normalize(vector)

This function normalise the vector

distance(vector1, vector2)

Returns the magnitude of the distance between the two vectors given

copy(vector)

Returns a copy of the given vector

limit(vector, scalar)

Limits the magnitud of the given vector

dot(vector1, vector2)

This function returns the dot product of the two vectors given

mag(vector)

This functions returns the margnitud of the given vector

moveTowards(start, end, speed, stop)

Moves the first vector given to the second vector given with the given speed and wont move if the magnitude of the distance is smaller than the stop parameter.

angleBetween(vector1, vector2)

Returns the angle between 2 vectors

setMag(vector, scalar)

Sets the magnitud of the vector to the length of the scalar given

toDegree(radian)

Converts a number from radian to degree

toRadian(degree)

Converts a number from degree to radian

cross3d(vector1, vector2)

Returns the cross product of 2 vectors with 3 components

cross2d(vector1, vector2)

Returns the cross product of 2 vectors with 2 components

angle(vector)

Returns the angle of the vector

angleMagnitude(direction, magnitud)

Creates a vector from a magnitud and a direction

linearIntersect(vector, angle)

Sets the angle of the given vector to the given angle

addAngle(vector, angle, piv)

Adds the angle of the given vector to the given angle

setAngle(vector, angle)

Sets the angle of the given vector to the given angle

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

About

A set of functions to manipulate vectors in javascript

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published