@mathools/geometry v1.0.1
@mathools/gemoetry
@mathools geometry module for vector calcs
Installing
For install library is easy to install by cloning the repo. You can install trhought npm too: Local installation
npm install @mathools/geometryGlobal installation
npm install -g @mathools/geometryContains
Magnitude
mag([Vector|arguments])=>Decibels
mag2decibel(magnitude)=>Vector
Vector([arguments]) extends ArrayVector class extends Array with some utils function for Vectors calcs. Function that are allowed only with Vectors takesVector|argumentsas parameter, and automatically convert Array, Vector or arguments Array to a usable Vector. Every function that doesnt return a value, return the Vector object. Every function has both static and instance scope, and can be called in two way:Vector.function( myVector, arguments )ormyVector.function( arguments ).
NB: arguments isn't an Array of numbers but the Array argument of the function, so it is possible to call a function in three way: function(0,1,2,3) or function([0,1,2,3]) or function(new Vector(0,1,2,3)) and the result are the same
has(index,fallback)=> return the index-th-component of the vector if present, fallback otherwise scalarmag(magnitude)=> if nomagnitudereturn the Vector's magnitude scalar, else set it and return the Vectordecibel()=> convert the Vector's magnitude to decibels scalaraddMag(value)=> add thevalueto the magnitudesubMag(value)=> subtract thevaluefrom the magnitudelimit(limit)=> constrain the magnitude to be less thanlimitset([arguments])=> set the components of the VecotrselfMap(callback(currValue,index,array))=> set the Vector's components with the results of callingcallbackfunction on every component (Array.map + Vector.set)add([Vector|arguments])=> add theargumentsto the Vector's componentssub([Vector|arguments])=> subtract theargumentsto the Vector's componentsmul([arguments])=> multilpy each component with the argumentsdiv([arguments])=> divide each component with the argumentsinvert()=> set-componentof each componentinverse()=> set1/componentof each componentnormalize()=> set the magnitude to 1 (Normalized Vector)dot(Vector|arguments)=> return the dot product between two Vectors ()lerp(value, [Vector|arguments])=> subract theargumentsand multiply it byvaluecopy()=> return a copy of the Vectorabs()=> set each component to his absolute valuesign()=> set each component to his sign valuecut(i)=> set to 0 the ith-component of the vectorlead(i)=> set tocomponent/magnitudethe ith-component of the vectorproject(i)=> set 0 all components except the ith-component that is setted as magnituderound(decimals)=> round all components withdecimalsapproximationfloor(decimals)=> floor all components withdecimalsapproximationceil(decimals)=> ceil all components withdecimalsapproximationrandom(decimals)=> set every component to random value withdecimalsapproximationsetAngle(angleXY, angleXZ)=> set angle of the Vectorrotate(angleXY, angleXZ)=> rotate of an angle the Vectorangle(i)=> return a the angle of the ith-component with the 0th-component axis (X-Axis) scalarangle2(i,j)=> return the angle of the ith-component with the j-th component axis scalarangleBetween(Vector|arguments)=> return the angle between two Vector scalarsolidAngle()=> return an Array of angles[ angleXY, angleXZ, angleYZ ][scalar[]]spaceAngle()=> return an Array of angles[ angleX, angleY, angleZ ][scalar[]]distance(Vector|arguments)=> return the distance between two Vectors scalarorthographic(scaleX,scaleZ)=> orthographic projection - set the Vector's 3D components to[ x*scaleX, y*scaleZ, 0 ]perspective()=> perspective - set the Vector's 3D components to[ x/z, y/z, 0 ]Contacts
If you like the project feel free to contact me on my
.
Something gone wrong? Feel free to rise an issue!
Did you like this project and it was usefull? Help me improve my work: