1.8.0 • Published 3 years ago

@seregpie/vector-math v1.8.0

Weekly downloads
7
License
MIT
Repository
github
Last release
3 years ago

VectorMath

A collection of mathematical functions for working with vectors.

setup

npm

npm i @seregpie/vector-math

Import inside an ES module.

import VectorMath from '@seregpie/vector-math';

or

Import inside a CommonJS module.

let VectorMath = require('@seregpie/vector-math');

browser

<script src="https://unpkg.com/@seregpie/vector-math"></script>

The module is globally available as VectorMath.

members

.add(vector, otherVector)

Adds the second vector to the first vector.

argumentdescription
vectorAn array as the first vector.
otherVectorAn array as the second vector.

Returns a new array as the calculated result.


.addScalar(vector, scalar)

Adds the scalar to the vector.

argumentdescription
vectorAn array as the vector.
scalarA number as the scalar.

Returns a new array as the calculated result.


.sub(vector, otherVector)

Subtracts the second vector from the first vector.

argumentdescription
vectorAn array as the first vector.
otherVectorAn array as the second vector.

Returns a new array as the calculated result.


.subScalar(vector, scalar)

Subtracts the scalar from the vector.

argumentdescription
vectorAn array as the vector.
scalarA number as the scalar.

Returns a new array as the calculated result.


.mul(vector, otherVector)

Multiplies the first vector by the second vector.

argumentdescription
vectorAn array as the first vector.
otherVectorAn array as the second vector.

Returns a new array as the calculated result.


.mulScalar(vector, scalar)

Multiplies the vector by the scalar.

argumentdescription
vectorAn array as the vector.
scalarA number as the scalar.

Returns a new array as the calculated result.


.div(vector, otherVector)

Divides the first vector by the second vector.

argumentdescription
vectorAn array as the first vector.
otherVectorAn array as the second vector.

Returns a new array as the calculated result.


.divScalar(vector, scalar)

Divides the vector by the scalar.

argumentdescription
vectorAn array as the vector.
scalarA number as the scalar.

Returns a new array as the calculated result.


.dot(vector, otherVector)

Calculates the dot product of the two vectors.

argumentdescription
vectorAn array as the first vector.
otherVectorAn array as the second vector.

Returns a number as the calculated result.


.abs(vector)

Makes the components of the vector absolute.

argumentdescription
vectorAn array as the vector.

Returns a new array as the calculated result.


.min(...vectors)

Calculates the min of the multiple vectors.

argumentdescription
...vectorsMultiple arguments where each argument is an array as the vector.

Returns a new array as the calculated result.


.max(...vectors)

Calculates the max of the multiple vectors.

argumentdescription
...vectorsMultiple arguments where each argument is an array as the vector.

Returns a new array as the calculated result.


.sum(...vectors)

Calculates the sum of the multiple vectors.

argumentdescription
...vectorsMultiple arguments where each argument is an array as the vector.

Returns a new array as the calculated result.


.mean(...vectors)

Calculates the mean of the multiple vectors.

argumentdescription
...vectorsMultiple arguments where each argument is an array as the vector.

Returns a new array as the calculated result.


.length(vector)

Calculates the length of a vector.

argumentdescription
vectorAn array as the vector.

Returns a number as the calculated result.


.setLength(vector, length)

Changes the length of the vector.

argumentdescription
vectorAn array as the vector.
lengthA number as the new length.

Returns a new array as the calculated result.


.normalize(vector)

Normalizes the vector.

argumentdescription
vectorAn array as the vector.

Returns a new array as the calculated result.


.distance(vector, otherVector)

alias EuclideanDistance

Calculates the euclidean distance between the two vectors.

argumentdescription
vectorAn array as the first vector.
otherVectorAn array as the second vector.

Returns a number as the calculated result.


.angle(vector, otherVector)

Calculates the angle between the two vectors in radians.

argumentdescription
vectorAn array as the first vector.
otherVectorAn array as the second vector.

Returns a number as the calculated result.


.clamp(vector, minVector, maxVector)

Clamps the vector between the two vectors.

argumentdescription
vectorAn array as the vector.
minVectorAn array as the minimum vector.
maxVectorAn array as the maximum vector.

Returns a new array as the calculated result.


.clampScalar(vector, minScalar, maxScalar)

Clamps the vector between the two scalars.

argumentdescription
vectorAn array as the vector.
minScalarA number as the minimum scalar.
maxScalarA number as the maximum scalar.

Returns a new array as the calculated result.


.clampLength(vector, minLength, maxLength)

Clamps the vector between the two lengths.

argumentdescription
vectorAn array as the vector.
minLengthA number as the minimum length.
maxLengthA number as the maximum length.

Returns a new array as the calculated result.


.scale(vector, oldMinVector, oldMaxVector, newMinVector, newMaxVector)

Scales the vector from a vector range to another.

argumentdescription
vectorAn array as the vector.
oldMinVectorAn array as the old minimum vector.
oldMaxVectorAn array as the old maximum vector.
newMinVectorAn array as the new minimum vector.
newMaxVectorAn array as the new maximum vector.

Returns a new array as the calculated result.


.scaleScalar(array: vector, oldMinScalar, oldMaxScalar, newMinScalar, newMaxScalar)

Scales the vector from a scalar range to another.

argumentdescription
vectorAn array as the vector.
oldMinScalarA number as the old minimum scalar.
oldMaxScalarA number as the old maximum scalar.
newMinScalarA number as the new minimum scalar.
newMaxScalarA number as the new maximum scalar.

Returns a new array as the calculated result.


.scaleLength(vector, oldMinLength, oldMaxLength, newMinLength, newMaxLength)

Scales the vector from a length range to another.

argumentdescription
vectorAn array as the vector.
oldMinLengthA number as the old minimum length.
oldMaxLengthA number as the old maximum length.
newMinLengthA number as the new minimum length.
newMaxLengthA number as the new maximum length.

Returns a new array as the calculated result.


.AngularDistance(vector, otherVector)

.AngularSimilarity(vector, otherVector)

.CosineDistance(vector, otherVector)

.CosineSimilarity(vector, otherVector)

.Covariance(vector, otherVector)

.DirectionalDistance(vector, otherVector)

.DirectionalMean(...vectors)

.ManhattanDistance(vector, otherVector)

.PearsonCorrelationCoefficient(vector, otherVector)

1.8.0

3 years ago

1.7.0

4 years ago

1.6.0

4 years ago

1.5.0

4 years ago

1.4.0

4 years ago

1.3.0

4 years ago

1.2.1

4 years ago

1.2.0

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.0.0

4 years ago