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:
-
outArraythe receiving vector
-
aArraythe first operand
-
bArraythe 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:
-
outArray -
aArray -
bArray -
cArray
Returns:
The out object
clone
-
a
Creates a new vec2 initialized with values from an existing vector
Parameters:
-
aArrayvector to clone
Returns:
a new 2D vector
copy
-
out -
a
Copy the values from one vec2 to another
Parameters:
-
outArraythe receiving vector
-
aArraythe 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:
-
aArray -
bArray
Returns:
crossVZ
-
out -
vec -
zcomp
Cross product between a vector and the Z component of a vector
Parameters:
-
outArray -
vecArray -
zcompNumber
Returns:
crossZV
-
out -
zcomp -
vec
Cross product between a vector and the Z component of a vector
Parameters:
-
outArray -
zcompNumber -
vecArray
Returns:
dist
()
static
Alias for vec2.distance
distance
-
a -
b
Calculates the euclidian distance between two vec2's
Parameters:
-
aArraythe first operand
-
bArraythe second operand
Returns:
distance between a and b
div
()
static
Alias for vec2.divide
divide
-
out -
a -
b
Divides two vec2's
Parameters:
-
outArraythe receiving vector
-
aArraythe first operand
-
bArraythe second operand
Returns:
out
dot
-
a -
b
Calculates the dot product of two vec2's
Parameters:
-
aArraythe first operand
-
bArraythe second operand
Returns:
dot product of a and b
fromValues
-
x -
y
Creates a new vec2 initialized with the given values
Parameters:
-
xNumberX component
-
yNumberY component
Returns:
a new 2D vector
getLineSegmentsIntersection
-
out -
p0 -
p1 -
p2 -
p3
Get the intersection point between two line segments.
Parameters:
-
outArray -
p0Array -
p1Array -
p2Array -
p3Array
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:
-
p0Array -
p1Array -
p2Array -
p3Array
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:
-
aArrayvector to calculate length of
Returns:
length of a
lerp
-
out -
a -
b -
t
Linearly interpolate/mix two vectors.
Parameters:
-
outArray -
aArrayFirst vector
-
bArraySecond vector
-
tNumberLerp factor
mul
()
static
Alias for vec2.multiply
multiply
-
out -
a -
b
Multiplies two vec2's
Parameters:
-
outArraythe receiving vector
-
aArraythe first operand
-
bArraythe second operand
Returns:
out
negate
-
out -
a
Negates the components of a vec2
Parameters:
-
outArraythe receiving vector
-
aArrayvector to negate
Returns:
out
normalize
-
out -
a
Normalize a vec2
Parameters:
-
outArraythe receiving vector
-
aArrayvector to normalize
Returns:
out
reflect
-
out -
vector -
normal
Reflect a vector along a normal.
Parameters:
-
outArray -
vectorArray -
normalArray
rotate
-
out -
a -
angle
Rotate a vector by an angle
Parameters:
-
outArray -
aArray -
angleNumber
rotate90cw
-
out -
a -
angle
Rotate a vector 90 degrees clockwise
Parameters:
-
outArray -
aArray -
angleNumber
scale
-
out -
a -
b
Scales a vec2 by a scalar number
Parameters:
-
outArraythe receiving vector
-
aArraythe vector to scale
-
bNumberamount to scale the vector by
Returns:
out
set
-
out -
x -
y
Set the components of a vec2 to the given values
Parameters:
-
outArraythe receiving vector
-
xNumberX component
-
yNumberY 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:
-
aArraythe first operand
-
bArraythe second operand
Returns:
squared distance between a and b
squaredLength
-
a
Calculates the squared length of a vec2
Parameters:
-
aArrayvector to calculate squared length of
Returns:
squared length of a
str
-
vec
Returns a string representation of a vector
Parameters:
-
vecArrayvector 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:
-
outArraythe receiving vector
-
aArraythe first operand
-
bArraythe second operand
Returns:
out
toGlobalFrame
-
out -
localPoint -
framePosition -
frameAngle
Transform a point position to global frame.
Parameters:
-
outArray -
localPointArray -
framePositionArray -
frameAngleNumber
toGlobalFrame
-
out -
localVector -
frameAngle
Transform a point position to global frame.
Parameters:
-
outArray -
localVectorArray -
frameAngleNumber
toLocalFrame
-
out -
worldPoint -
framePosition -
frameAngle
Transform a point position to local frame.
Parameters:
-
outArray -
worldPointArray -
framePositionArray -
frameAngleNumber
vectorToLocalFrame
-
out -
worldVector -
frameAngle
Transform a vector to local frame.
Parameters:
-
outArray -
worldVectorArray -
frameAngleNumber
