Constructor
# new DuVector(components)
Constructs a new Vector
Parameters:
Name | Type | Description |
---|---|---|
components |
Array.<Number>
|
The components of the vector, one number per dimension |
Methods
# static fromPoints(pointA, pointB) → {DuVector}
Creates a vector from two points
Parameters:
Name | Type | Description |
---|---|---|
pointA |
Array.<Number>
|
The origin of the vector |
pointB |
Array.<Number>
|
The end of the vector |
# static unit(axis, dimensions) → {DuVector}
Creates a unit vector
Parameters:
Name | Type | Description |
---|---|---|
axis |
Number
|
The unit axis |
dimensions |
Number
|
The number of dimensions |
# add(other) → {DuVector}
Addition
Parameters:
Name | Type | Description |
---|---|---|
other |
DuVector
|
The vector to add |
The result
# angle(other) → {Number}
Gets the angle between the two vectors
Parameters:
Name | Type | Description |
---|---|---|
other |
DuVector
|
The angle in degrees
Number
# dot(other) → {Number}
Dot Product
Parameters:
Name | Type | Description |
---|---|---|
other |
DuVector
|
The other vector |
Number
# hasOppositeDirection(other) → {Boolean}
Checks if the two vectors have an opposite direction
Parameters:
Name | Type | Description |
---|---|---|
other |
DuVector
|
Boolean
# hasSameDirection(other) → {Boolean}
Checks if the two vectors have the same direction
Parameters:
Name | Type | Description |
---|---|---|
other |
DuVector
|
Boolean
# isPerpendicular(other) → {Boolean}
Checks if the two vectors are perpendicular
Parameters:
Name | Type | Description |
---|---|---|
other |
DuVector
|
Boolean
# normalize() → {DuVector}
Create a normalized vector (with length equal to 1)
The normalized vector
# orientation2D(other) → {Number}
Checks the orientation of the angle between 2D vectors
Parameters:
Name | Type | Description |
---|---|---|
other |
DuVector
|
1
: counter-clockwiser, -1
: clockwise, 0
: alignedNumber
# orientedAngle(other) → {Number}
Gets the angle between the two 2D vectors
Parameters:
Name | Type | Description |
---|---|---|
other |
DuVector
|
Number
# projectOn(other) → {DuVector}
Projects the vector on another vector
Parameters:
Name | Type | Description |
---|---|---|
other |
DuVector
|
# scale(factor) → {DuVector}
Scale
Parameters:
Name | Type | Description |
---|---|---|
factor |
Number
|
The scale factor |
The result
# setLength(newLength) → {DuVector}
Sets a new length for the vector
Parameters:
Name | Type | Description |
---|---|---|
newLength |
Number
|