new Vector2d(
x?,y?):Vector2d
Creates a vector from coordinates.
If all coordinates are omitted, the vector is created with coordinates (0, 1). If y is omitted while x is provided, y defaults to 0.
number
X coordinate of 2D vector.
number
Y coordinate of 2D vector.
Vector2d
new Vector2d(
start,end):Vector2d
Creates a vector from start to end.
Start point.
End point.
Vector2d
get x():
number
X coordinate of the vector.
number
set x(
x):void
Sets the X coordinate of the vector.
number
X coordinate.
void
get y():
number
Y coordinate of the vector.
number
set y(
y):void
Sets the Y coordinate of the vector.
number
Y coordinate.
void
add(
other):this
Adds the coordinates of other to this vector.
Vector2d
Other vector.
this
added(
other):Vector2d
Returns a new vector resulting from adding other to this vector.
Vector2d
Other vector.
Vector2d
angle(
other):number
Returns the angle between this vector and other.
Vector2d
Other vector.
number
clone():
Vector2d
Creates a new vector with the same coordinates as this vector.
Vector2d
copy(
other):this
Copies the coordinates of other to this vector.
Vector2d
Vector to copy.
this
crossed(
other):number
Returns the scalar cross product of this vector and other.
Vector2d
Other vector.
number
divide(
scalar):this
Divides the coordinates of this vector by scalar.
number
Scalar value.
this
divided(
scalar):Vector2d
Returns a new vector resulting from dividing this vector by scalar.
number
Scalar value.
Vector2d
dot(
other):number
Returns the dot product of this vector and other.
Vector2d
Other vector.
number
staticfromXY(xy):Vector2d
Creates a vector from an object implementing the BaseXY interface.
Object implementing BaseXY interface.
Vector2d
get(
index):number
Returns the coordinate value of the vector:
index equals 0index equals 1Throws a RangeError if index is not in the range [0, 1].
number
Coordinate index.
number
isEqual(
other,tolerance?):boolean
Returns whether this vector is equal to other within the provided coordinate tolerance.
Vector2d
Other 2D vector.
number = Vector2d.coincidenceTolerance
Coordinate comparison tolerance (1e-9 by default).
boolean
isNormal(
other,tolerance?):boolean
Returns whether other is perpendicular to this vector within the provided angular tolerance.
Vector2d
Other vector.
number = Vector2d.angularTolerance
Angular comparison tolerance (1e-7 by default).
boolean
isOpposite(
other,tolerance?):boolean
Returns whether other is opposite to this vector within the provided angular tolerance.
Vector2d
Other vector.
number = Vector2d.angularTolerance
Angular comparison tolerance (1e-7 by default).
boolean
isParallel(
other,tolerance?):boolean
Returns whether other is parallel to this vector within the provided angular tolerance.
Vector2d
Other vector.
number = Vector2d.angularTolerance
Angular comparison tolerance (1e-7 by default).
boolean
length():
number
Returns the length of the vector.
number
multiplied(
other):Vector2d
Returns a new vector resulting from multiplying this vector by other.
Vector2d
Other vector.
Vector2d
multiplied(
matrix):Vector2d
Returns a new vector resulting from multiplying this vector by matrix.
2D matrix.
Vector2d
multiplied(
scalar):Vector2d
Returns a new vector resulting from multiplying this vector by scalar.
number
Scalar value.
Vector2d
multiply(
other):this
Multiplies the coordinates of this vector by the coordinates of other component-wise.
Vector2d
Other vector.
this
multiply(
matrix):this
Multiplies the coordinates of this vector by a 2D matrix.
2D matrix.
this
multiply(
scalar):this
Multiplies the coordinates of this vector by a scalar value.
number
Scalar value.
this
normalize():
this
Normalizes the coordinates of this vector.
this
normalized():
Vector2d
Returns a new vector with normalized coordinates of this vector.
Vector2d
reverse():
this
Reverses the coordinates of this vector.
this
reversed():
Vector2d
Returns a new vector resulting from reversing this vector.
Vector2d
set(
index,value):this
Sets the coordinate value of the vector:
index equals 0index equals 1Throws a RangeError if index is not in the range [0, 1].
number
Coordinate index.
number
Coordinate value.
this
setCoord(
x?,y?):this
Sets the specified coordinates of the vector.
number
X coordinate of 2D vector.
number
Y coordinate of 2D vector.
this
setX(
x):this
Sets the X coordinate of the vector.
number
X coordinate.
this
setY(
y):this
Sets the Y coordinate of the vector.
number
Y coordinate.
this
squareLength():
number
Returns the squared length of the vector.
number
subtract(
other):this
Subtracts the coordinates of other from this vector.
Vector2d
Other vector.
this
subtracted(
other):Vector2d
Returns a new vector resulting from subtracting other from this vector.
Vector2d
Other vector.
Vector2d
toJSON():
BaseXY
Returns the JSON representation of this vector.
toString(
precision?):string
Returns a string representation of this vector with the provided precision.
number = 3
Precision.
string
transform(
transformation):this
Transforms this vector according to transformation.
Only the rotation and scale factor of the transformation affect the vector. Translation is ignored.
Transformation.
this
transformed(
transformation):Vector2d
Returns a new vector resulting from transforming this vector.
Transformation.
Vector2d