new Vector()
The Vector object represents a location in a two-dimensional coordinate system, where x represents the horizontal axis and y represents the vertical axis.
Prefer Vector.create for new instances.
Members
Methods
-
<static> create( [x] [, y])
-
Create a vecotr instance. This is prefered than
new Vector()
since
the instance may come from the pool.Parameters:
Name Type Argument Description x
number <optional>
Position of the point on the x axis
y
number <optional>
Position of the point on the y axis
Returns:
Vector instance
- Type
- Vector
-
<static> recycle(vector)
-
Recycle a
Vector
instance into the pool for later use.Parameters:
Name Type Description vector
Vector Vector instance to be recycled.
- Source:
- See:
-
add(x [, y])
-
Add to vector values.
Parameters:
Name Type Argument Description x
number | Vector Number or
Vector
to add to self.y
number <optional>
Number to add to
y
.Returns:
Self for chaining.
- Type
- Vector
-
angle( [vector])
-
Get angle vector angle or angle between two vectors.
Parameters:
Name Type Argument Description vector
Vector <optional>
Target vector to calculate with, angle of self is returned when it is not provided.
Returns:
Angle between self and target.
- Type
- number
-
angleFromOrigin(vector)
-
Get angle between two vectors from origin.
Parameters:
Name Type Description vector
Vector The vector to calculate angle from.
Returns:
Angle.
- Type
- number
-
clone()
-
Clone this vector.
Returns:
The cloned vector.
- Type
- Vector
-
copy(v)
-
Copy values from another vector.
Parameters:
Name Type Description v
Vector Vector to copy from.
Returns:
Self for chaining.
- Type
- Vector
-
distance(vector)
-
Get distance of two vectors.
Parameters:
Name Type Description vector
Vector Target vector to calculate distance from.
Returns:
Distance.
- Type
- number
-
divide(x [, y])
-
Divide self by another vector or 2 numbers.
Parameters:
Name Type Argument Description x
number | Vector Number or
Vector
to divide.y
number <optional>
Number to divide by.
Returns:
Self for chaining.
- Type
- Vector
-
dot( [vector])
-
Dot operation with another vector.
Parameters:
Name Type Argument Description vector
Vector <optional>
Vector to dot with.
Returns:
Result of dot operation.
- Type
- number
-
dotNormalized( [vector])
-
Get normalized dot of vector.
Parameters:
Name Type Argument Description vector
Vector <optional>
Vector to dot with
Returns:
Result of the dot operation.
- Type
- number
-
equals(vector)
-
Returns true if the given point is equal to this point
Parameters:
Name Type Description vector
Vector Vector to compare to.
Returns:
Whether the two vectors are equal
- Type
- boolean
-
length()
-
Get length of vector.
Returns:
Length of this vector.
- Type
- number
-
limit(vector)
-
Limit vector values.
Parameters:
Name Type Description vector
Vector Clamp this vector to a limitation(vector)
Returns:
Self for chaining.
- Type
- Vector
-
multiply(x [, y])
-
Multiply self with another vector or 2 numbers.
Parameters:
Name Type Argument Description x
number | Vector Number or
Vector
to multiply.y
number <optional>
Number to multiply to
y
.Returns:
Self for chaining.
- Type
- Vector
-
normalize()
-
Normalize vector.
Returns:
Self for chaining
- Type
- Vector
-
perp()
-
Change this vector to be perpendicular to what it was before. (Effectively
roatates it 90 degrees in a clockwise direction)Returns:
Self for chaining.
- Type
- Vector
-
project(other)
-
Project this vector on to another vector.
Parameters:
Name Type Description other
Vector The vector to project onto
Returns:
Self for chaining.
- Type
- Vector
-
projectN(other)
-
Project this vector onto a vector of unit length. This is slightly more efficient
thanproject
when dealing with unit vectors.Parameters:
Name Type Description other
Vector The unit vector to project onto
Returns:
Self for chaining.
- Type
- Vector
-
reflect(axis)
-
Reflect this vector on an arbitrary axis.
Parameters:
Name Type Description axis
Vector The vector representing the axis
Returns:
Self for chaining.
- Type
- Vector
-
reflectN(axis)
-
Reflect this vector on an arbitrary axis (represented by a unit vector). This is
slightly more efficient thanreflect
when dealing with an axis that is a unit vector.Parameters:
Name Type Description axis
Vector The unit vector representing the axis
Returns:
Self for chaining.
- Type
- Vector
-
reverse()
-
Reverse this vector
Returns:
Self for chaining.
- Type
- Vector
-
rotate(angle)
-
Rotate vector in radians.
Parameters:
Name Type Description angle
number Angle to rotate.
Returns:
Self for chaining.
- Type
- Vector
-
round()
-
Round vector values.
Returns:
Self for chaining
- Type
- Vector
-
set( [x] [, y])
-
Set vector values.
Parameters:
Name Type Argument Default Description x
number <optional>
0 Position of the point on the x axis
y
number <optional>
0 Position of the point on the y axis
Returns:
Vector itself for chaining.
- Type
- Vector
-
sign(vector)
-
Check whether the direction from self to other vector is clockwise.
Parameters:
Name Type Description vector
Vector Vector to calculate from
Returns:
Result (1 = CW, -1 = CCW)
- Type
- number
-
squaredDistance(vector)
-
Get squared euclidian distance of two vectors.
Parameters:
Name Type Description vector
Vector Target vector to calculate distance from.
Returns:
Squared distance value.
- Type
- number
-
squaredLength()
-
Get squared length of vector.
Returns:
Squared length of this vector.
- Type
- number
-
subtract(x [, y])
-
Subtract from vector values.
Parameters:
Name Type Argument Description x
number | Vector Number or
Vector
to subtract from.y
number <optional>
Number to subtract from
y
.Returns:
Self for chaining.
- Type
- Vector