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

vanilla-vectors-3d

v1.0.1

Published

A library that provides vectors, lines and planes in a three-dimensional vector space

Downloads

17

Readme

Vanilla Vectors 3D

Build Status

A small library with vectors, lines and planes that allows for some simple vector geometry calculations. Written in plain vanilla JS, hence the name.

Installation

npm install --save vanilla-vectors-3d

Usage (ES6)

Create a vector with P(1/2/3):

import { Vector, Line, Plane } from 'vanilla-vectors-3d'

const v = new Vector(1, 2, 3)

Do some calculations:

const v1 = new Vector(1, 2, 3)
const v2 = new Vector(4, 5, 6)

// Subtract
v1.minus(v2) // === Vector(-3, -3, -3)

// Add
v1.plus(v2) // === Vector(5, 7, 9)

// Multiply with a scalar
v1.timesScalar(3) // === Vector(3, 6, 9)

// Cross product of two vectors
v1.cross(v2) // === Vector(-3, 6, -3)

// Scalar product of two vectors
v1.scalarProduct(v2) // === -24

// Length
v1.length // === 3.741...

// Transform vector to a length of 1
v1.normalize() // === Vector(0.26..., 0.53..., 0.80...)

// Rotate around an axis
const v3 = new Vector(1, 0, 0)
v3.rotate('y', 90) // === Vector(0, 0, -1)

// Rotate around a line represented by its normal vector
v3.rotateAroundVector(v1.normalize(), 90)

// Rotate around Line object
v3.rotateAroundLine(new Line(v1, v2), 90)

// Check if one vector is a multiple of another
v1.isLinearlyDependentOn(v2) // === false

// Check if two vectors are equal
v1.isEqualTo(v2)

// Apply a transformation matrix
v1.applyTransformationMatrix([[1, 0, 0], [0, 1, 0], [0, 0, 1]]) //  === v1

Also lines are given:

const v1 = new Vector(1, 1, 1)
const v2 = new Vector(2, 2, 2)

const l = new Line(v1, v2)

// Rotate line around two axes X and Z
l.rotate(180, 180)

// Rotate line around another line
const v3 = new Vector(4, 5, 6)
const v4 = new Vector(7, 8, 9)

l.rotateAroundLine(new Line(v3, v4), 90)

As well as planes:

const v1 = new Vector(0, 0, 0)
const v2 = new Vector(1, 0, 0)
const v3 = new Vector(0, 1, 0)

const p = new Plane(v1, v2, v3)

// Calculate an intersection vector with a given line
const v4 = new Vector(1, 1, 1)
const v5 = new Vector(1, 1, -1)
const l = new Line(v4, v5)

p.getIntersectionWith(l) // Vector if one point exists, null if Line is within Plane or parallel