vec2 Class
The vec2 object from glMatrix, with some extensions and some removed methods. See http://glmatrix.net.
Item Index
Methods
- add static
- centroid static
- clone static
- copy static
- create static
- crossLength static
- crossVZ static
- crossZV static
- dist static
- distance static
- div static
- divide static
- dot static
- fromValues static
- getLineSegmentsIntersection static
- getLineSegmentsIntersectionFraction static
- len static
- length static
- lerp static
- mul static
- multiply static
- negate static
- normalize static
- reflect static
- rotate static
- rotate90cw static
- scale static
- set static
- sqrDist static
- sqrLen static
- squaredDistance static
- squaredLength static
- str static
- sub static
- subtract static
- toGlobalFrame
- toGlobalFrame
- toLocalFrame
- vectorToLocalFrame
Methods
add
-
out
-
a
-
b
Adds two vec2's
Parameters:
-
out
Arraythe receiving vector
-
a
Arraythe first operand
-
b
Arraythe second operand
Returns:
out
centroid
-
out
-
a
-
b
-
c
Compute centroid of a triangle spanned by vectors a,b,c. See http://easycalculation.com/analytical/learn-centroid.php
Parameters:
-
out
Array -
a
Array -
b
Array -
c
Array
Returns:
The out object
clone
-
a
Creates a new vec2 initialized with values from an existing vector
Parameters:
-
a
Arrayvector to clone
Returns:
a new 2D vector
copy
-
out
-
a
Copy the values from one vec2 to another
Parameters:
-
out
Arraythe receiving vector
-
a
Arraythe source vector
Returns:
out
create
()
Array
static
Creates a new, empty vec2
Returns:
a new 2D vector
crossLength
-
a
-
b
Make a cross product and only return the z component
Parameters:
-
a
Array -
b
Array
Returns:
crossVZ
-
out
-
vec
-
zcomp
Cross product between a vector and the Z component of a vector
Parameters:
-
out
Array -
vec
Array -
zcomp
Number
Returns:
crossZV
-
out
-
zcomp
-
vec
Cross product between a vector and the Z component of a vector
Parameters:
-
out
Array -
zcomp
Number -
vec
Array
Returns:
dist
()
static
Alias for vec2.distance
distance
-
a
-
b
Calculates the euclidian distance between two vec2's
Parameters:
-
a
Arraythe first operand
-
b
Arraythe second operand
Returns:
distance between a and b
div
()
static
Alias for vec2.divide
divide
-
out
-
a
-
b
Divides two vec2's
Parameters:
-
out
Arraythe receiving vector
-
a
Arraythe first operand
-
b
Arraythe second operand
Returns:
out
dot
-
a
-
b
Calculates the dot product of two vec2's
Parameters:
-
a
Arraythe first operand
-
b
Arraythe second operand
Returns:
dot product of a and b
fromValues
-
x
-
y
Creates a new vec2 initialized with the given values
Parameters:
-
x
NumberX component
-
y
NumberY component
Returns:
a new 2D vector
getLineSegmentsIntersection
-
out
-
p0
-
p1
-
p2
-
p3
Get the intersection point between two line segments.
Parameters:
-
out
Array -
p0
Array -
p1
Array -
p2
Array -
p3
Array
Returns:
True if there was an intersection, otherwise false.
getLineSegmentsIntersectionFraction
-
p0
-
p1
-
p2
-
p3
Get the intersection fraction between two line segments. If successful, the intersection is at p0 + t * (p1 - p0)
Parameters:
-
p0
Array -
p1
Array -
p2
Array -
p3
Array
Returns:
A number between 0 and 1 if there was an intersection, otherwise -1.
len
()
static
Alias for vec2.length
length
-
a
Calculates the length of a vec2
Parameters:
-
a
Arrayvector to calculate length of
Returns:
length of a
lerp
-
out
-
a
-
b
-
t
Linearly interpolate/mix two vectors.
Parameters:
-
out
Array -
a
ArrayFirst vector
-
b
ArraySecond vector
-
t
NumberLerp factor
mul
()
static
Alias for vec2.multiply
multiply
-
out
-
a
-
b
Multiplies two vec2's
Parameters:
-
out
Arraythe receiving vector
-
a
Arraythe first operand
-
b
Arraythe second operand
Returns:
out
negate
-
out
-
a
Negates the components of a vec2
Parameters:
-
out
Arraythe receiving vector
-
a
Arrayvector to negate
Returns:
out
normalize
-
out
-
a
Normalize a vec2
Parameters:
-
out
Arraythe receiving vector
-
a
Arrayvector to normalize
Returns:
out
reflect
-
out
-
vector
-
normal
Reflect a vector along a normal.
Parameters:
-
out
Array -
vector
Array -
normal
Array
rotate
-
out
-
a
-
angle
Rotate a vector by an angle
Parameters:
-
out
Array -
a
Array -
angle
Number
rotate90cw
-
out
-
a
-
angle
Rotate a vector 90 degrees clockwise
Parameters:
-
out
Array -
a
Array -
angle
Number
scale
-
out
-
a
-
b
Scales a vec2 by a scalar number
Parameters:
-
out
Arraythe receiving vector
-
a
Arraythe vector to scale
-
b
Numberamount to scale the vector by
Returns:
out
set
-
out
-
x
-
y
Set the components of a vec2 to the given values
Parameters:
-
out
Arraythe receiving vector
-
x
NumberX component
-
y
NumberY component
Returns:
out
sqrDist
()
static
Alias for vec2.squaredDistance
sqrLen
()
static
Alias for vec2.squaredLength
squaredDistance
-
a
-
b
Calculates the squared euclidian distance between two vec2's
Parameters:
-
a
Arraythe first operand
-
b
Arraythe second operand
Returns:
squared distance between a and b
squaredLength
-
a
Calculates the squared length of a vec2
Parameters:
-
a
Arrayvector to calculate squared length of
Returns:
squared length of a
str
-
vec
Returns a string representation of a vector
Parameters:
-
vec
Arrayvector to represent as a string
Returns:
string representation of the vector
sub
()
static
Alias for vec2.subtract
subtract
-
out
-
a
-
b
Subtracts two vec2's
Parameters:
-
out
Arraythe receiving vector
-
a
Arraythe first operand
-
b
Arraythe second operand
Returns:
out
toGlobalFrame
-
out
-
localPoint
-
framePosition
-
frameAngle
Transform a point position to global frame.
Parameters:
-
out
Array -
localPoint
Array -
framePosition
Array -
frameAngle
Number
toGlobalFrame
-
out
-
localVector
-
frameAngle
Transform a point position to global frame.
Parameters:
-
out
Array -
localVector
Array -
frameAngle
Number
toLocalFrame
-
out
-
worldPoint
-
framePosition
-
frameAngle
Transform a point position to local frame.
Parameters:
-
out
Array -
worldPoint
Array -
framePosition
Array -
frameAngle
Number
vectorToLocalFrame
-
out
-
worldVector
-
frameAngle
Transform a vector to local frame.
Parameters:
-
out
Array -
worldVector
Array -
frameAngle
Number