Constructor
new Vector(ps, pe)
Vector may be constructed by two points, or by two float numbers,
or by array of two numbers
- Source:
Parameters:
Name | Type | Description |
---|---|---|
ps |
Point
|
start point |
pe |
Point
|
end point |
Members
Methods
add(v) → {Vector}
Return result of addition of other vector to this vector as a new vector
- Source:
Parameters:
Name | Type | Description |
---|---|---|
v |
Vector
|
Other vector |
Returns:
- Type:
-
Vector
angleTo(v) → {number}
Return angle between this vector and other vector.
Angle is measured from 0 to 2*PI in the counter clockwise direction from current vector to other.
Angle is measured from 0 to 2*PI in the counter clockwise direction from current vector to other.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
v |
Vector
|
Another vector |
Returns:
- Type:
-
number
clone() → {Vector}
Method clone returns new instance of Vector
- Source:
Returns:
- Type:
-
Vector
cross(v) → {number}
Returns vector product (cross product) of two vectors
cross_product = (this x v)
- Source:
Parameters:
Name | Type | Description |
---|---|---|
v |
Vector
|
Other vector |
Returns:
- Type:
-
number
dot(v) → {number}
Returns scalar product (dot product) of two vectors
dot_product = (this * v)
- Source:
Parameters:
Name | Type | Description |
---|---|---|
v |
Vector
|
Other vector |
Returns:
- Type:
-
number
equalTo(v) → {boolean}
Returns true if vectors are equal up to DP_TOL
tolerance
- Source:
Parameters:
Name | Type | Description |
---|---|---|
v |
Vector
|
Returns:
- Type:
-
boolean
invert() → {Vector}
Return inverted vector
- Source:
Returns:
- Type:
-
Vector
multiply(scalar) → {Vector}
Returns new vector multiplied by scalar
- Source:
Parameters:
Name | Type | Description |
---|---|---|
scalar |
number
|
Returns:
- Type:
-
Vector
normalize() → {Vector}
Returns unit vector.
Throw error if given vector has zero length
Throw error if given vector has zero length
- Source:
Returns:
- Type:
-
Vector
projectionOn(v) → {Vector}
Return vector projection of the current vector on another vector
- Source:
Parameters:
Name | Type | Description |
---|---|---|
v |
Vector
|
Another vector |
Returns:
- Type:
-
Vector
rotate(angle) → {Vector}
Returns new vector rotated by given angle,
positive angle defines rotation in counter clockwise direction,
negative - in clockwise direction
- Source:
Parameters:
Name | Type | Description |
---|---|---|
angle |
number
|
Angle in radians |
Returns:
- Type:
-
Vector
rotate90CCW() → {Vector}
Returns vector rotated 90 degrees counter clockwise
- Source:
Returns:
- Type:
-
Vector
rotate90CW() → {Vector}
Returns vector rotated 90 degrees clockwise
- Source:
Returns:
- Type:
-
Vector
subtract(v) → {Vector}
Return result of subtraction of other vector from current vector as a new vector
- Source:
Parameters:
Name | Type | Description |
---|---|---|
v |
Vector
|
Another vector |
Returns:
- Type:
-
Vector
toJSON() → {Object}
This method returns an object that defines how data will be
serialized when called JSON.stringify() method
- Source:
Returns:
- Type:
-
Object