All Projects → evanshortiss → vector2d

evanshortiss / vector2d

Licence: MIT license
2D Vector Library. Operates using Objects, Array or Float32Array types to allow flexible performance.

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to vector2d

vecti
A tiny TypeScript library for 2D vector math.
Stars: ✭ 14 (-50%)
Mutual labels:  math, vector, 2d
matrixgl
Yet another matrix library for WebGL
Stars: ✭ 25 (-10.71%)
Mutual labels:  math, vector
footile
A 2D vector graphics library written in Rust
Stars: ✭ 32 (+14.29%)
Mutual labels:  vector, 2d
vector-math
Shader-math in haxe: library for GLSL vector operations, complete with swizzles and all
Stars: ✭ 30 (+7.14%)
Mutual labels:  math, vector
Unitymathreference
Math reference for games and more. All visualized in Unity3D.
Stars: ✭ 166 (+492.86%)
Mutual labels:  math, 2d
Black
World's fastest HTML5 2D game engine   🛸
Stars: ✭ 174 (+521.43%)
Mutual labels:  math, 2d
abacus
📐 C# cross precision 3D maths library.
Stars: ✭ 35 (+25%)
Mutual labels:  math, vectors
Algebra
means completeness and balancing, from the Arabic word الجبر
Stars: ✭ 92 (+228.57%)
Mutual labels:  math, vector
nmu
neg4n's mathematics utilities
Stars: ✭ 17 (-39.29%)
Mutual labels:  vector, vector2d
Tensor
A library and extension that provides objects for scientific computing in PHP.
Stars: ✭ 146 (+421.43%)
Mutual labels:  math, vector
vg
Vector-geometry toolbelt for 3D points and vectors
Stars: ✭ 106 (+278.57%)
Mutual labels:  vector, vectors
Math Php
Powerful modern math library for PHP: Features descriptive statistics and regressions; Continuous and discrete probability distributions; Linear algebra with matrices and vectors, Numerical analysis; special mathematical functions; Algebra
Stars: ✭ 2,009 (+7075%)
Mutual labels:  math, vector
Hlslpp
Math library using hlsl syntax with SSE/NEON support
Stars: ✭ 153 (+446.43%)
Mutual labels:  math, vector
Mathnet Spatial
Math.NET Spatial
Stars: ✭ 246 (+778.57%)
Mutual labels:  math, 2d
Numphp
Mathematical PHP library for scientific computing
Stars: ✭ 120 (+328.57%)
Mutual labels:  math, vector
SCNMathExtensions
Math extensions for SCNVector3, SCNQuaternion, SCNMatrix4
Stars: ✭ 32 (+14.29%)
Mutual labels:  math, vector
vec-la-fp
↗️ A tiny (functional) 2d linear algebra library
Stars: ✭ 21 (-25%)
Mutual labels:  math, vector
Sophus
C++ implementation of Lie Groups using Eigen.
Stars: ✭ 1,048 (+3642.86%)
Mutual labels:  math, 2d
Spatialmath Python
Create, manipulate and convert representations of position and orientation in 2D or 3D using Python
Stars: ✭ 78 (+178.57%)
Mutual labels:  math, 2d
Mathematics for Machine Learning
Learn mathematics behind machine learning and explore different mathematics in machine learning.
Stars: ✭ 28 (+0%)
Mutual labels:  math, vector

Vector2D - 2D Vectors for TypeScript & JavaScript

Travis CI Coverage Status TypeScript

Documentation

Detailed documentation is available here.

Installation and Usage

Install via npm:

npm install vector2d

Usage with JavaScript:

var Vec2D = require('vector2d');

const v = new Vec2D.Vector(2, 3)

Usage with TypeScript/ES6:

import * as Vec2D from 'vector2d'

const v = new Vec2D.Vector(2, 3)

It's also possible to use this module directly in the browser through window.Vec2D. Simply clone the code locally and run the following:

npm install
npm run browserify
npm run uglify

This will produce vec2d.js and vec2d.min.js files in dist/ the folder of the repository that you can include via <script> tags.

About

An easy to use 2D Vector library with 3 methods of Vector representation to optimise for your particular use case.

Vector2D provides 3 main modes of Vector representations (classes):

  • Vec2D.ArrayVector
  • Vec2D.Float32Vector
  • Vec2D.Vector

The different representations is really more of an experiment than a necessity since for most users Vector or ArrayVector types will be fine.

Regardless of the class used all methods can be used in the same manner and you don't need to worry about the underlying representation.

API

Vector Instance Methods

All instance methods modify the underlying vector where possible. For example calling multiplyByScalar will multiply the vector x and y components by the provided number and return the updated vector itself (a reference to this) rather than a new instance. The benefit if this is that less objects are created which reduces garbage collection and makes chaining possible.

If you don't want to modfy the vector itself you can call v.clone() and modify the newly returned vector instead. Here's an example.

const av0 = new Vec2D.ArrayVector(10, 0)
const av1 = new Vec2D.ArrayVector(0, 5)

// Methods are chainable where you'd expect
const newVec = av0.clone().add(av1);
newVec.toString(); // (10, 5)

// Original vector hasn't changed!
av0.toString(); // (10, 0)

setAxes(x, y)

Set the x and y values of this vector.

toString()

Convert vector to a String with format "(0, 0)"

toArray()

Convert vector to standard JavaScript Array [2.823, 1.541]

toObject()

Covert vector to a JSON object with format { x: 1.4, y: 8 }.

add(vector)

Modify this vector by adding the provided vector to it.

subtract(vector)

Modify this vector by subtracting the provided vector from it.

equals(vector)

Check does this vector equal the provided vector.

mulV(vector)

Multiply this vector by provided vector.

divV(vector)

Divide this vector by provided vector.

mulS(number)

Multiply this vector by a number.

divS(number)

Divide this vector by a number.

dot(vector)

Returns dot product from this vector and the provided vector.

cross(vector)

Returns cross product from this vector and the provided vector.

reverse()

Reverse the values in this vector.

abs()

Convert stored values to absolute values.

distance(vec)

Find the distance between this vector and the provided vec;

zero()

Set vector values to 0.

rotate(radians)

Rotate vector by provided radians.

clone()

Returns a clone of this vector.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].