GpsGate Server JavaScript API

Vec2  1.0.0

GpsGate Server JavaScript API > Vec2 > Franson.Vec2
Search:
 
Filters

static Class Franson.Vec2

namespace

Properties

Epsilon - private float

for comparisons. Set to your likings. see setEpsilon/getEpsilon see equals

Methods

add

Vec2 add(a, b)
note: supports multiple arguments
Parameters:
a <Vec2>
b <Vec2>
Returns: Vec2
a + b

angle

number angle(u, [v=x_axis])
angle between two vectors in radians. (-Pi, Pi).
Parameters:
u <Vec2>
[v=x_axis] <Vec2> Note: in this case the angle is within [0, 2*Math.Pi)
Returns: number
(-Pi, Pi)

determinant

number determinant(a, b)
Equiv to the magnitude of the z-comp of the cross product of a & b in the x-y plane. sin(t)|a||b|=det(a,b) = 2*area of the spanned triangle
Parameters:
a <Vec2>
b <Vec2>
Returns: number

dot

number dot(u, v)
Dot product (inner-product, scalar-product, ( = |u||v|*cos(theta) )
Parameters:
u <Vec2>
v <Vec2>
Returns: number
a.b

equals

boolean equals(a, b, [epsilon=Franson.Vec2.getEpsilon()])
Parameters:
a <Vec2>
b <Vec2>
[epsilon=Franson.Vec2.getEpsilon()] <Number>
Returns: boolean
a == b? (within epsilon tolerance)

getEpsilon

number getEpsilon()
Epsilon used for Vec2 comparison. see equals
Returns: number

isVec2Like

boolean isVec2Like(v)
You should assume this is the precondition (PC, assertion) for all vector operations. todo: support multiple parameters to match Mochi-conventions? todo: alias as isPointLike?
Parameters:
v <Object>
Returns: boolean

length

number length(v)
alias for norm
Parameters:
v <Vec2>
Returns: number
Euclidian length of vector

lerp

Vec2 lerp(t, p0, p1)
LinEar inteRPolation
Parameters:
t <float> (0..1) t=0 => p0, t=1 => p1
p0 <Vec2>
p1 <Vec2>
Returns: Vec2

negate

Vec2 negate(v)
definition: add(v, negate(v))) == (0,0)
Parameters:
v <Vec2>
Returns: Vec2
-v

norm

number norm(v)
Magnitude(length) of vector (add as alias?)
Parameters:
v <Vec2>
Returns: number
Euclidian length of vector

normalize

number normalize(v)
normalizes v (|v|=1) and returns the old norm note: this is the only mutable operation!
Parameters:
v <Vec2>
Returns: number
previous norm (before normalization)

ortho

Vec2 ortho(v)
definition: dot(v, ortho(v)) == 0 todo: provide a param (or two versions?) controlling which direction the flip should take? (CW, CCW)
Parameters:
v <Vec2>
Returns: Vec2
vector v rotated 90 degrees

scale

Vec2 scale(s, v)
s*v (or v*s if scalar-vector arguments are reversed) or element-vise multiplication(scale) if both arguments are Vec2s.
Parameters:
s <Number|Vec2>
v <Vec2|Number>
Returns: Vec2
s*v

setEpsilon

void setEpsilon(epsilon)
Epsilon used for Vec2 comparison. see equals
Parameters:
epsilon <number>
Returns: void

sub

Vec2 sub(a, b)
note: supports multiple arguments
Parameters:
a <Vec2>
b <Vec2>
Returns: Vec2
a - b


Copyright © 2009 Franson Technology AB, Sweden. All rights reserved.