npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@seregpie/vector-math

v1.8.0

Published

A collection of mathematical functions for working with vectors.

Downloads

151

Readme

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.

| argument | description | | ---: | :--- | | vector | An array as the first vector. | | otherVector | An array as the second vector. |

Returns a new array as the calculated result.


.addScalar(vector, scalar)

Adds the scalar to the vector.

| argument | description | | ---: | :--- | | vector | An array as the vector. | | scalar | A number as the scalar. |

Returns a new array as the calculated result.


.sub(vector, otherVector)

Subtracts the second vector from the first vector.

| argument | description | | ---: | :--- | | vector | An array as the first vector. | | otherVector | An array as the second vector. |

Returns a new array as the calculated result.


.subScalar(vector, scalar)

Subtracts the scalar from the vector.

| argument | description | | ---: | :--- | | vector | An array as the vector. | | scalar | A number as the scalar. |

Returns a new array as the calculated result.


.mul(vector, otherVector)

Multiplies the first vector by the second vector.

| argument | description | | ---: | :--- | | vector | An array as the first vector. | | otherVector | An array as the second vector. |

Returns a new array as the calculated result.


.mulScalar(vector, scalar)

Multiplies the vector by the scalar.

| argument | description | | ---: | :--- | | vector | An array as the vector. | | scalar | A number as the scalar. |

Returns a new array as the calculated result.


.div(vector, otherVector)

Divides the first vector by the second vector.

| argument | description | | ---: | :--- | | vector | An array as the first vector. | | otherVector | An array as the second vector. |

Returns a new array as the calculated result.


.divScalar(vector, scalar)

Divides the vector by the scalar.

| argument | description | | ---: | :--- | | vector | An array as the vector. | | scalar | A number as the scalar. |

Returns a new array as the calculated result.


.dot(vector, otherVector)

Calculates the dot product of the two vectors.

| argument | description | | ---: | :--- | | vector | An array as the first vector. | | otherVector | An array as the second vector. |

Returns a number as the calculated result.


.abs(vector)

Makes the components of the vector absolute.

| argument | description | | ---: | :--- | | vector | An array as the vector. |

Returns a new array as the calculated result.


.min(...vectors)

Calculates the min of the multiple vectors.

| argument | description | | ---: | :--- | | ...vectors | Multiple 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.

| argument | description | | ---: | :--- | | ...vectors | Multiple 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.

| argument | description | | ---: | :--- | | ...vectors | Multiple 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.

| argument | description | | ---: | :--- | | ...vectors | Multiple 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.

| argument | description | | ---: | :--- | | vector | An array as the vector. |

Returns a number as the calculated result.


.setLength(vector, length)

Changes the length of the vector.

| argument | description | | ---: | :--- | | vector | An array as the vector. | | length | A number as the new length. |

Returns a new array as the calculated result.


.normalize(vector)

Normalizes the vector.

| argument | description | | ---: | :--- | | vector | An 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.

| argument | description | | ---: | :--- | | vector | An array as the first vector. | | otherVector | An array as the second vector. |

Returns a number as the calculated result.


.angle(vector, otherVector)

Calculates the angle between the two vectors in radians.

| argument | description | | ---: | :--- | | vector | An array as the first vector. | | otherVector | An array as the second vector. |

Returns a number as the calculated result.


.clamp(vector, minVector, maxVector)

Clamps the vector between the two vectors.

| argument | description | | ---: | :--- | | vector | An array as the vector. | | minVector | An array as the minimum vector. | | maxVector | An array as the maximum vector. |

Returns a new array as the calculated result.


.clampScalar(vector, minScalar, maxScalar)

Clamps the vector between the two scalars.

| argument | description | | ---: | :--- | | vector | An array as the vector. | | minScalar | A number as the minimum scalar. | | maxScalar | A number as the maximum scalar. |

Returns a new array as the calculated result.


.clampLength(vector, minLength, maxLength)

Clamps the vector between the two lengths.

| argument | description | | ---: | :--- | | vector | An array as the vector. | | minLength | A number as the minimum length. | | maxLength | A 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.

| argument | description | | ---: | :--- | | vector | An array as the vector. | | oldMinVector | An array as the old minimum vector. | | oldMaxVector | An array as the old maximum vector. | | newMinVector | An array as the new minimum vector. | | newMaxVector | An 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.

| argument | description | | ---: | :--- | | vector | An array as the vector. | | oldMinScalar | A number as the old minimum scalar. | | oldMaxScalar | A number as the old maximum scalar. | | newMinScalar | A number as the new minimum scalar. | | newMaxScalar | A 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.

| argument | description | | ---: | :--- | | vector | An array as the vector. | | oldMinLength | A number as the old minimum length. | | oldMaxLength | A number as the old maximum length. | | newMinLength | A number as the new minimum length. | | newMaxLength | A 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)