Package Exports
- @feldhaus/vector
- @feldhaus/vector/dist/index.cjs.js
- @feldhaus/vector/dist/index.esm.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@feldhaus/vector) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
@feldhaus/vector
A lightweight vector utility library that provides commonly used vector operations for JavaScript and TypeScript applications.
Installation
You can install the package via npm:
npm install @feldhaus/vectorAvailable Functions
- add: Adds two vectors. Source
- sub: Subtracts the second vector from the first. Source
- mult: Multiplies a vector by a scalar. Source
- div: Divides a vector by a scalar. Source
- mag: Calculates the magnitude of a vector. Source
- magSqr: Calculates the squared magnitude of a vector. Source
- angleBetween: Calculates the angle between two vectors. Source
- distanceBetween: Calculates the distance between two vectors. Source
Examples
import { add, sub, mult, div } from '@feldhaus/vector';
const vectorA = [1, 2];
const vectorB = [3, 4];
const addedVector = add(vectorA, vectorB); // Output: { x: 4, y: 6 }
const subtractedVector = sub(vectorA, vectorB); // Output: { x: -2, y: -2 }
const multipliedVector = mult(vectorA, 2); // Output: { x: 2, y: 4 }
const dividedVector = div(vectorA, 2); // Output: { x: 0.5, y: 1 }import { mag, magSqr } from '@feldhaus/vector';
const vectorA = [1, 2];
const vectorB = [3, 4];
const magnitude = mag(vectorA); // Output: 2.23606797749979
const magnitudeSquared = magSqr(vectorA); // Output: 5import { angleBetween, distanceBetween } from '@feldhaus/vector';
const vectorA = [1, 0];
const vectorB = [0, 1];
const angle = angleBetween(vectorA, vectorB); // Output: 1.5707963267948966 (which is π/2 radians or 90 degrees)
const distance = distanceBetween(vectorA, vectorB); // Output: : 1.41