new Vector(x, y)
Constructor for the minimal requirements for being a Vector.
Parameters:
| Name | Type | Description |
|---|---|---|
x |
Number | |
y |
Number |
- Source:
Members
-
x :Number
-
x-coordinate of the vector
Type:
- Number
- Source:
-
y :Number
-
y-coordinate of the vector
Type:
- Number
- Source:
Methods
-
<static> add(vector1, vector2 [, newObj])
-
Perform vector addition
Parameters:
Name Type Argument Default Description vector1Vector The first vector
vector2Vector The second vector
newObjBoolean <optional>
true Boolean that determines the return value. If true, then it returns a new Vector object
vectorsuch thatvector.x === vector1.x + vector2.xandvector.x === vector1.y + vector2.yIf false, then
vector2.xis added tovector1.x,vector2.yis added tovector1.yand thenvector1is returned.- Source:
Returns:
- The sum of the two vectors. New object if
newObjis true. Returnsvector1otherwise.
- Type
- Vector
-
<static> applyTransformation(a11, a12, a21, a22, x, y)
-
Apply a linear transformation defined by a 2x2 matrix to a vector.
Parameters:
Name Type Description a11Number Element found in row 1, column 1
a12Number Element found in row 1, column 2
a21Number Element found in row 2, column 1
a22Number Element found in row 2, column 2
xNumber x-coordinate of vector to be transformed
yNumber y-coordinate of vector to be transformed
- Source:
Returns:
- The transformed vector
-
<static> distance(vector1, vector2)
-
Get distance between two vectors.
Parameters:
Name Type Description vector1Vector vector2Vector - Source:
Returns:
- The vector distance
-
<static> divide(vector, scalar)
-
Divide a vector by a scalar
Parameters:
Name Type Description vectorVector scalarNumber - Source:
Returns:
- Type
- Vector
-
<static> dotProduct(vector1, vector2)
-
Calculate dot product of
vector1andvector2.Parameters:
Name Type Description vector1Vector vector2Vector - Since:
-
- 0.2.0-alpha
- Source:
Returns:
- The dot product
- Type
- Number
-
<static> getLength(vector)
-
Get length of the vector
Parameters:
Name Type Description vectorVector - Source:
Returns:
- The length of the vector
- Type
- Number
-
<static> rotate(x, y, a)
-
Rotate a vector (x,y) by angle a
Parameters:
Name Type Description xNumber x-coordinate
yNumber y-coordinate
aNumber Angle in radians
- Source:
Returns:
- Type
- Vector
-
<static> scale(vector, scalar)
-
Multiply a vector by a scalar
Parameters:
Name Type Description vectorVector scalarNumber - Source:
Returns:
- Type
- Vector
-
<static> subtract(vector1, vector2)
-
Perform vector subtraction
Parameters:
Name Type Description vector1Vector vector2Vector - @param {Boolean} [newObj = true] - Boolean that determines the return value.
If true, then it returns a new Vector object
vectorsuch thatvector.x === vector1.x - vector2.xandvector.x === vector1.y - vector2.y
If false, then
vector2.xis subtracted fromvector1.x,vector2.yis subtracted fromvector1.yand thenvector1is returned.- Source:
Returns:
- The difference between the two vectors. New object if
newObjis true. Returnsvector1otherwise.
- Type
- Vector
- @param {Boolean} [newObj = true] - Boolean that determines the return value.
If true, then it returns a new Vector object
-
<static> svgVector(x, y)
-
Get SVG point
Parameters:
Name Type Description xNumber yNumber - Source:
Returns:
- SVG Vector String
- Type
- String
-
<static> unitVector(vector)
-
Get normalized vector of some vector.
Parameters:
Name Type Description vectorVector Vector to normalize.
- Source:
Returns:
- The Unit Vector
- Type
- Vector
-
<static> vectorToArray(vertex, ray1, ray2)
-
Gets angle between two lines that both end at
vertex.That is, suppose that
Ais the pointray1,Bis the pointray2and thatCis the pointvertex. Then,vectorToArrayreturns the angle between the linesACandBC.Parameters:
Name Type Description vertexVector ray1Vector ray2Vector - Since:
-
- 0.2.0-alpha
- Source:
Returns:
- The angle
- Type
- Number