Skip to content

Latest commit

 

History

History
183 lines (142 loc) · 4.61 KB

Vector2D.md

File metadata and controls

183 lines (142 loc) · 4.61 KB

Vector2D

Kind: global class
Npmpackage:

new Vector2D(x, y)

A simple 2D Vector class

Import from ad-geom

Param Type
x number
y number

Example

import { Vector2D } from 'ad-geom'
var myVector1 = new Vector2D(0, 320)
var myVector2 = new Vector2D(-3, 5.5)

Vector2D.add(v) ⇒ Vector2D

Adds another vector to itself

Kind: static method of Vector2D

Param Type
v Vector2D

Example

myVector1.add(myVector2)

Vector2D.sub(v) ⇒ Vector2D

Subtracts another vector from itself

Kind: static method of Vector2D

Param Type
v Vector2D

Example

myVector1.sub(myVector2)

Vector2D.dist(v) ⇒ number

Kind: static method of Vector2D
Returns: number - The distance between two vectors as locations

Param Type
v Vector2D

Example

var distance = myVector.dist(myVector2)

Vector2D.mult(s)

Multiplies X and Y of the vector by s

Kind: static method of Vector2D

Param Type
s Number

Example

myVector.mult(10.3)

Vector2D.div(s) ⇒ Vector2D

Divides X and Y of the vector by s

Kind: static method of Vector2D

Param Type
s Number

Example

myVector.div(2)

Vector2D.limit(s) ⇒ Vector2D

Limits the length of the vector if it's longer than s

Kind: static method of Vector2D

Param Type
s Number

Example

myVector.limit(18.2)

Vector2D.length() ⇒ Number

Kind: static method of Vector2D
Returns: Number - The length of the vector.
Example

var length = myVector.length()

Vector2D.normalize() ⇒ Vector2D

Normalizes the vector( ie scale the vector to length of 1 )

Kind: static method of Vector2D
Example

myVector.normalize()

Vector2D.clone() ⇒ Vector2D

Creates a new Vector2D with and same x and y

Kind: static method of Vector2D
Example

var newVecotor = myVector.clone()

Vector2D.degreeToVector() ⇒ Vector2D

Converts a degree 0 - 360 to a normalized vector

Kind: static method of Vector2D
Example

var myVecotor = Vector2D.degreeToVector(45)

Vector2D.random(degreeIncrement) ⇒ Vector2D

Returns a random normalized vector

Kind: static method of Vector2D

Param Type Description
degreeIncrement Number Optional, the degree increment of the random vector, defaults to 0.01

Example

var myVecotor1 = Vector2D.random()
var myVecotor2 = Vector2D.random(1)