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

e-vector

v1.0.1

Published

A 2D or 3D Euclidean vector library for Node.js and the browser.

Downloads

1

Readme

E-Vector

This is a library to work with two or three dimensional Euclidean vectors.

Installation

Install using npm,

npm install --save e-vector

Use as ES Module

import Vector from "e-vector";

API Docs

Table of Contents

Vector

packages/e-vector/src/e-vector.js:22-26

Create a vector by specifying its components.

Parameters

  • x number Value of the x component
  • y number Value of the y component
  • z number Value of the z component. If it is not provided, it is assumed to be zero (optional, default 0)

Examples

const v = Vector(3, 4);
const u = Vector(3, 4, 5);

Returns Vector

copy

packages/e-vector/src/e-vector.js:41-41

Create a copy of the given vector.

Parameters

Examples

var v = Vector(3, 4);
var u = Vector.copy(v);

u.toString(); // Vector(3, 4, 0)

Returns Vector A vector with the same components as the given vector

fromAngle

packages/e-vector/src/e-vector.js:54-54

Create a new 2D unit vector from the given angle (in radians).

Parameters

Examples

var v = Vector.fromAngle(Math.atan2(4, 3));
v.toString(); // Vector(0.6, 0.8, 0)

Returns Vector A new vector with heading equal to given angle and a magnitude of 1

equals

packages/e-vector/src/e-vector.js:73-73

Check the equality of two vectors.

Examples

const u = Vector(3, 4);
const v = Vector(4, 5);
const w = Vector(3, 4);

Vector.equals(u, v); // false
Vector.equals(u, w); // true
u === w; // false

Returns boolean true if the vectors are equal

mag

packages/e-vector/src/e-vector.js:81-81

Compute the magnitude of the vector.

Parameters

Returns number Magnitude of the given vector.

magSq

packages/e-vector/src/e-vector.js:89-89

Compute the square of magnitude of the vector.

Parameters

Returns number Square of magnitude of the given vector.

add

packages/e-vector/src/e-vector.js:98-98

Add two vectors.

Parameters

Returns Vector Resultant vector.

sub

packages/e-vector/src/e-vector.js:107-109

Subtract the second vector from the first.

Parameters

Returns Vector Vector result of v - u.

mul

packages/e-vector/src/e-vector.js:118-118

Multiply the vector with a scalar.

Parameters

  • n number Scalar value to multiply the vector.
  • v Vector The vector

Returns Vector The resultant vector.

div

packages/e-vector/src/e-vector.js:127-130

Divide the vector with a scalar.

Parameters

  • n number Scalar value to divide the vector.
  • v Vector The vector

Returns Vector If the scalar is 0, return Vector(0, 0), else compute the vector.

dist

packages/e-vector/src/e-vector.js:139-141

Compute euclidean distance between two vectors.

Parameters

Returns number The distance between v and u.

dot

packages/e-vector/src/e-vector.js:151-151

Compute the dot product of two vectors.

Parameters

Returns number The result of uv.

cross

packages/e-vector/src/e-vector.js:161-166

Compute the cross product of two vectors. Only defined for three dimensional vectors.

Parameters

Returns Vector The result of u × v.

normalize

packages/e-vector/src/e-vector.js:174-174

Change the magnitude/length of the vector to 1 without changing its angle/direction.

Parameters

Returns Vector Vector with magnitude of 1 and direction same as u.

setMag

packages/e-vector/src/e-vector.js:183-183

Set the magnitude/length of the vector without changing its angle/direction.

Parameters

Returns Vector A new vector with magnitude of m and direction same as u.

heading

packages/e-vector/src/e-vector.js:191-191

Compute the direction/angle of the vector in radians.

Parameters

Returns number Angle in radians

project

packages/e-vector/src/e-vector.js:200-202

Returns the projection of the second vector onto the first.

Parameters

  • on Vector The vector on which the second vector will be projected.

Returns Vector The projected vector.

round

packages/e-vector/src/e-vector.js:216-216

Returns new vector with it's components rounded.

Parameters

Examples

var u = Vector(10.2, 10.9);
var roundedVector = Vector.round(u);
console.log(roundedVector); // Vector(10, 11)

Returns Vector v

ceil

packages/e-vector/src/e-vector.js:230-230

Returns new vector with the nearest non-fractional values for the components.

Parameters

Examples

var u = Vector(10.2, 10.9);
var ceilVector = Vector.ceil(u);
console.log(ceilVector); // Vector(11, 11)

Returns Vector v

floor

packages/e-vector/src/e-vector.js:244-244

Returns new vector with the nearest smaller non-fractional values for the components.

Parameters

Examples

var u = Vector(10.2, 10.9);
var floorVector = Vector.floor(u);
console.log(floorVector); // Vector(10, 10)

Returns Vector v

abs

packages/e-vector/src/e-vector.js:258-258

Returns new vector with the absolute values for the components.

Parameters

Examples

var u = Vector(-5, 10);
var absVector = Vector.abs(u);
console.log(absVector); // Vector(5, 10)

Returns Vector v

License

See LICENSE.md