Members
-
<static, readonly> DIRECTION
-
Map of vectors for 9 directions separated by 45 degrees each.
- Source:
- See:
Properties:
Name Type Description NONE
Vector2 | Object vector corresponding to no direction LEFT
Vector2 | Object vector corresponding to left direction RIGHT
Vector2 | Object vector corresponding to right direction UP
Vector2 | Object vector corresponding to up direction DOWN
Vector2 | Object vector corresponding to down direction UPLEFT
Vector2 | Object vector corresponding to up left direction UPRIGHT
Vector2 | Object vector corresponding to up right direction DOWNLEFT
Vector2 | Object vector corresponding to DOWNLEFT direction DOWNRIGHT
Vector2 | Object vector corresponding to down right direction -
<static> Q_1 :number
-
Flag for quadrant 1, -x, -y
- Source:
- See:
-
<static> Q_2 :number
-
Flag for quadrant 2, x, -y
- Source:
- See:
-
<static> Q_3 :number
-
Flag for quadrant 2, -x, y
- Source:
- See:
-
<static> Q_4 :number
-
Flag for quadrant 2, x, y
- Source:
- See:
Methods
-
<static> abs(v) → {Vector2|Object}
-
Absolutes 2d vector values.
Parameters:Name Type Description v
Vector2 | Object vector object or plain object with vector properties - Source:
{ Vector2 | Object } 2d vector or plain object with properties of a 2d vector -
<static> add(a, b) → {Vector2|Object}
-
Adds vector source into target. IMPORTANT:this modifies target vector in place.
Parameters:Name Type Description a
Vector2 | Object vector target b
Vector2 | Object vector source - Source:
{ Vector2 | Object } 2d vector or plain object with properties of a 2d vector -
<static> addScalar(v, s) → {Vector2|Object}
-
Add scalar to vector target. IMPORTANT:this modifies target vector in place.
Parameters:Name Type Description v
Vector2 | Object vector target s
Number scalar - Source:
{ Vector2 | Object } 2d vector or plain object with properties of a 2d vector -
<static> addVectors(a, b) → {Vector2|Object}
-
Adds two vectors and creates a new vector.
Parameters:Name Type Description a
Vector2 | Object vector b
Vector2 | Object vector - Source:
{ Vector2 | Object } 2d vector or plain object with properties of a 2d vector -
<static> centerOfPoints(points) → {Vector2|Object}
-
Finds center of a set of points.
Parameters:Name Type Description points
Array array of points. - Source:
{ Vector2 | Object } 2d vector or plain object with properties of a 2d vector -
<static> clone(v) → {Vector2|Object}
-
Generates a plain object with properties of a 2d vector by copying another.
Parameters:Name Type Description v
Vector2 | Object vector object or plain object with vector properties - Source:
{ Vector2 | Object } 2d vector or plain object with properties of a 2d vector -
<static> copy(a, b) → {Vector2|Object}
-
Copies target 2d vector into source. IMPORTANT:this modifies target vector in place.
Parameters:Name Type Description a
Vector2 | Object vector target b
Vector2 | Object vector source - Source:
{ Vector2 | Object } 2d vector or plain object with properties of a 2d vector -
<static> cross(a, b) → {Number}
-
Gets cross product of two vectors.
Parameters:Name Type Description a
Vector2 | Object vector b
Vector2 | Object vector - Source:
{ Number } cross product -
<static> crossFV(v, s) → {Number}
-
Gets cross product of vector and scalar where -s/s.
Parameters:Name Type Description v
Vector2 | Object vector s
Number scalar - Source:
{ Number } cross product -
<static> crossVF(v, s) → {Number}
-
Gets cross product of vector and scalar where s/-s.
Parameters:Name Type Description v
Vector2 | Object vector s
Number scalar - Source:
{ Number } cross product -
<static> directionThreshold(v, thresholdX, thresholdY) → {Vector2|Object}
-
Thresholds a 2d vector. IMPORTANT:this modifies target vector in place.
Parameters:Name Type Argument Default Description v
Object vector to convert thresholdX
Number <optional>
0 how close to zero direction x can be before becoming 0 thresholdY
Number <optional>
0 how close to zero direction y can be before becoming 0 - Source:
{ Vector2 | Object } 2d vector or plain object with properties of a 2d vector -
<static> directionToString(v) → {String}
-
Converts direction vector to string.
Parameters:Name Type Description v
Vector2 | Object vector to convert - Source:
- See:
{ String } uppercase string name of closest direction to vector -
<static> divide(a, b) → {Vector2|Object}
-
Divides vector source into target. IMPORTANT:this modifies target vector in place.
Parameters:Name Type Description a
Vector2 | Object vector target b
Vector2 | Object vector source - Source:
{ Vector2 | Object } 2d vector or plain object with properties of a 2d vector -
<static> divideScalar(v, s) → {Vector2|Object}
-
Divides scalar into vector target. IMPORTANT:this modifies target vector in place.
Parameters:Name Type Description v
Vector2 | Object vector target s
Number scalar - Source:
{ Vector2 | Object } 2d vector or plain object with properties of a 2d vector -
<static> divideVectors(a, b) → {Vector2|Object}
-
Divides two vectors and creates a new vector.
Parameters:Name Type Description a
Vector2 | Object vector b
Vector2 | Object vector - Source:
{ Vector2 | Object } 2d vector or plain object with properties of a 2d vector -
<static> dot(a, b) → {Number}
-
Gets dot product of two vectors.
Parameters:Name Type Description a
Vector2 | Object vector b
Vector2 | Object vector - Source:
{ Number } dot product -
<static> equal(a, b) → {Boolean}
-
Checks if 2 vectors are equal.
Parameters:Name Type Description a
Vector2 | Object vector b
Vector2 | Object vector - Source:
{ Boolean } whether vectors are equal -
<static> inverse(v) → {Vector2|Object}
-
Inverts 2d vector values. IMPORTANT:this modifies target vector in place.
Parameters:Name Type Description v
Vector2 | Object vector object or plain object with vector properties - Source:
{ Vector2 | Object } 2d vector or plain object with properties of a 2d vector -
<static> isAlmostZero(v) → {Boolean}
-
Checks 2d vector values to see if *almost* zero, based on ig.CONFIG.PRECISION_ZERO.
Parameters:Name Type Description v
Vector2 | Object vector object or plain object with vector properties - Source:
- See:
{ Boolean } whether vector is almost zero -
<static> isZero(v) → {Boolean}
-
Checks 2d vector values to see if zero.
Parameters:Name Type Description v
Vector2 | Object vector object or plain object with vector properties - Source:
{ Boolean } whether vector is zero -
<static> length(v) → {Number}
-
Gets length of 2d vector.
Parameters:Name Type Description v
Vector2 | Object vector object or plain object with vector properties - Source:
{ Number } 2d vector length -
<static> lengthSquared(v) → {Number}
-
Gets squared length of 2d vector.
Parameters:Name Type Description v
Vector2 | Object vector object or plain object with vector properties - Source:
{ Number } 2d vector length before square root -
<static> max(a, b) → {Vector2|Object}
-
Finds the max values of two vectors and creates a new vector.
Parameters:Name Type Description a
Vector2 | Object vector b
Vector2 | Object vector - Source:
{ Vector2 | Object } 2d vector or plain object with properties of a 2d vector -
<static> min(a, b) → {Vector2|Object}
-
Finds the min values of two vectors and creates a new vector.
Parameters:Name Type Description a
Vector2 | Object vector b
Vector2 | Object vector - Source:
{ Vector2 | Object } 2d vector or plain object with properties of a 2d vector -
<static> multiply(a, b) → {Vector2|Object}
-
Multiplies vector source by target. IMPORTANT:this modifies target vector in place.
Parameters:Name Type Description a
Vector2 | Object vector target b
Vector2 | Object vector source - Source:
{ Vector2 | Object } 2d vector or plain object with properties of a 2d vector -
<static> multiplyScalar(v, s) → {Vector2|Object}
-
Multiplies scalar by vector target. IMPORTANT:this modifies target vector in place.
Parameters:Name Type Description v
Vector2 | Object vector target s
Number scalar - Source:
{ Vector2 | Object } 2d vector or plain object with properties of a 2d vector -
<static> multiplyVectors(a, b) → {Vector2|Object}
-
Multiplies two vectors and creates a new vector.
Parameters:Name Type Description a
Vector2 | Object vector b
Vector2 | Object vector - Source:
{ Vector2 | Object } 2d vector or plain object with properties of a 2d vector -
<static> normalize(v) → {Vector2|Object}
-
Normalizes 2d vector.
Parameters:Name Type Description v
Vector2 | Object vector object or plain object with vector properties - Source:
{ Vector2 | Object } 2d vector or plain object with properties of a 2d vector -
<static> pointQuadrant(x, y, originX, originY) → {Number}
-
Finds the quadrant of a 2D point.
Parameters:Name Type Description x
Number X position y
Number Y position originX
Number origin x originY
Number origin y - Source:
{ Number } quadrants bitwise flag -
<static> pointsCW(p1, p2, p3) → {Number}
-
Finds if 3 points are clockwise. IMPORTANT: the first point is used as the pivot point.
Parameters:Name Type Description p1
Object point1 p2
Object point2 p3
Object point3 - Source:
{ Number } counter-clockwise if > 0, clockwise if < 0, and collinear if = 0. -
<static> pointsToConvexHull(points) → {Array}
-
Creates a convex hull shape from a set of points by Graham Scan in a clockwise direction.
Parameters:Name Type Description points
Array array of points - Source:
{ Array } sorted points -
<static> projectPoints(points, offsetX, offsetY, scaleX, scaleY, angle, angleOffsetX, angleOffsetY) → {Array}
-
Returns projected points.
Parameters:Name Type Argument Default Description points
Array points to project offsetX
Number <optional>
0 x offset. offsetY
Number <optional>
0 y offset. scaleX
Number <optional>
1 scale x applied before offset. scaleY
Number <optional>
1 scale y applied before offset. angle
Number <optional>
0 angle to rotate. angleOffsetX
Number <optional>
0 angle x offset. angleOffsetY
Number <optional>
0 angle y offset. - Source:
{ Array } projected points. -
<static> radianBetweenPoints(a, b, c) → {Number}
-
Gets signed radian between a and c from b.
Parameters:
- based on http://stackoverflow.com/questions/3486172/angle-between-3-pointsName Type Description a
Object 2D point b
Object 2D point c
Object 2D point - Source:
{ Number } signed radian -
<static> rotate(v, angle, originX, originY) → {Vector2|Object}
-
Rotates a 2d vector.
Parameters:Name Type Description v
Vector2 | Object vector angle
Number angle to rotate by originX
Number origin x / rotation point originY
Number origin y / rotation point - Source:
{ Vector2 | Object } 2d vector or plain object with properties of a 2d vector -
<static> set(v, x, y) → {Vector2|Object}
-
Sets 2d vector values. IMPORTANT:this modifies target vector in place.
Parameters:Name Type Description v
Vector2 | Object vector object or plain object with vector properties x
Number x position y
Number y position - Source:
{ Vector2 | Object } 2d vector or plain object with properties of a 2d vector -
<static> setScalar(v, s) → {Vector2|Object}
-
Sets 2d vector values from scalar. IMPORTANT:this modifies target vector in place.
Parameters:Name Type Description v
Vector2 | Object vector object or plain object with vector properties s
Number scalar - Source:
{ Vector2 | Object } 2d vector or plain object with properties of a 2d vector -
<static> subtract(a, b) → {Vector2|Object}
-
Subtracts vector source from target. IMPORTANT:this modifies target vector in place.
Parameters:Name Type Description a
Vector2 | Object vector target b
Vector2 | Object vector source - Source:
{ Vector2 | Object } 2d vector or plain object with properties of a 2d vector -
<static> subtractScalar(v, s) → {Vector2|Object}
-
Subtracts scalar from vector target. IMPORTANT:this modifies target vector in place.
Parameters:Name Type Description v
Vector2 | Object vector target s
Number scalar - Source:
{ Vector2 | Object } 2d vector or plain object with properties of a 2d vector -
<static> subtractVectors(a, b) → {Vector2|Object}
-
Subtracts two vectors and creates a new vector.
Parameters:Name Type Description a
Vector2 | Object vector b
Vector2 | Object vector - Source:
{ Vector2 | Object } 2d vector or plain object with properties of a 2d vector -
<static> vector(x, y, v) → {Vector2|Object}
-
Generates a plain object with properties of a 2d vector.
Parameters:Name Type Argument Description x
Number <optional>
x position y
Number <optional>
y position v
Vector2 | Object <optional>
vector object - Source:
{ Vector2 | Object } 2d vector or plain object with properties of a 2d vector -
<static> zero(v) → {Vector2|Object}
-
Zeroes 2d vector values. IMPORTANT:this modifies target vector in place.
Parameters:Name Type Description v
Vector2 | Object vector object or plain object with vector properties - Source:
{ Vector2 | Object } 2d vector or plain object with properties of a 2d vector