Skip to content
This repository has been archived by the owner on Jul 12, 2022. It is now read-only.
/ vector-math Public archive

Used for handling 2D Vectors and Vector Math

Notifications You must be signed in to change notification settings

Ketzzz-dev/vector-math

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

About

vector-math is an easy to use library for handling 2D Vectors and Vector math

  • Fast
  • Simple
  • Object-oriented

Installation

npm i --save @low-key/vector-math

Example Usage

import { Vector2, MathV } from "@low-key/vector-math";

class PhysicsBody {
	public position: Vector2;
	public velocity = Vector2.ZERO;
	public force = Vector2.ZERO;
	public gravity = new Vector2(0, 5);
	public mass: number;
	
	protected constructor(x: number, y: number, m: number) {
		this.position = new Vector2(x, y);
		this.mass = m;
	}
	
	public step(delta: number): void {
		this.force = MathV.multiply(this.gravity, this.mass);
		
		this.velocity = MathV.add(this.velocity, MathV.divide(this.force, this.mass * delta));
		this.position = MathV.add(this.position, MathV.multiply(this.velocity, delta));
	}
}

1.0.4 Changelog

  • Reduced MathV and Vector2 class into one single class

About

Used for handling 2D Vectors and Vector Math

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published