Constructor
new Vec2(xopt, yopt)
- Source:
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
x |
Number
|
<optional> |
0 |
The x component of the new Vector |
y |
Number
|
<optional> |
0 |
The y component of the new Vector |
Methods
add(other) → {UMath.Vec2}
Adds the specified Vector or scalar to this
(See UMath.Vec2.add
for a static version of this method)
- Source:
Parameters:
Name | Type | Description |
---|---|---|
other |
Number
|
UMath.Vec2
|
Vec2Object
|
The Vector or scalar to add |
cross(other) → {Number}
Calculates the Z value of the 3D cross product Vector between this and the specified Vector
- Source:
Parameters:
Name | Type | Description |
---|---|---|
other |
UMath.Vec2
|
The other Vector to calculate the cross product with |
Returns:
- Type:
-
Number
The Z value of the 3D cross product Vector
dist(other) → {Number}
Returns the distance between this and the specified Vector (See UMath.Vec2#distSq
)
- Source:
Parameters:
Name | Type | Description |
---|---|---|
other |
UMath.Vec2
|
Vec2Object
|
The other Vector |
Returns:
- Type:
-
Number
The distance between the two vectors
distSq(other) → {Number}
Returns the squared distance between this and the specified Vector (See UMath.Vec2#dist
)
- Source:
Parameters:
Name | Type | Description |
---|---|---|
other |
UMath.Vec2
|
Vec2Object
|
The other Vector |
Returns:
- Type:
-
Number
The squared distance between the two vectors
div(other) → {UMath.Vec2}
Divides this by the specified scalar
(See UMath.Vec2.div
for a static version of this method)
- Source:
Parameters:
Name | Type | Description |
---|---|---|
other |
Number
|
The scalar to add |
dot(other) → {Number}
Calculates the dot product between this and the specified Vector
- Source:
Parameters:
Name | Type | Description |
---|---|---|
other |
UMath.Vec2
|
The other Vector to calculate the dot product with |
Returns:
- Type:
-
Number
The dot product between this and the specified Vector
mag() → {Number}
Returns the magnitude of the Vector (See UMath.Vec2#magSq
)
- Source:
Returns:
- Type:
-
Number
The magnitude
magSq() → {Number}
Returns the squared magnitude of the Vector (See UMath.Vec2#mag
)
- Source:
Returns:
- Type:
-
Number
The squared magnitude
mul(other) → {UMath.Vec2}
Multiplies this by the specified scalar
(See UMath.Vec2.mul
for a static version of this method)
- Source:
Parameters:
Name | Type | Description |
---|---|---|
other |
Number
|
The scalar to add |
normalize() → {UMath.Vec2}
Makes the magnitude of this Vector equal to 1
(See UMath.Vec2.normalize
for a static version of this method)
- Source:
rotate(angle) → {UMath.Vec2}
Rotates this by the specified angle
(See UMath.Vec2.rotate
for a static version of this method)
- Source:
Parameters:
Name | Type | Description |
---|---|---|
angle |
Number
|
The angle to rotate this Vector by |
sub(other) → {UMath.Vec2}
Subtracts the specified Vector or scalar to this
(See UMath.Vec2.sub
for a static version of this method)
- Source:
Parameters:
Name | Type | Description |
---|---|---|
other |
Number
|
UMath.Vec2
|
Vec2Object
|
The Vector or scalar to subtract |
toString() → {String}
Returns this Vector as a String (e.g. "(0, 0)")
(See UMath.Vec2.fromString
to get a Vector from a String)
- Source:
Returns:
- Type:
-
String
This Vector as a String
(static) add(v, other) → {UMath.Vec2}
Returns a new Vector which is the sum of the two specified elements
(See UMath.Vec2#add
for a non-static version of this method)
- Source:
Parameters:
Name | Type | Description |
---|---|---|
v |
UMath.Vec2
|
Vec2Object
|
The Vector to add to |
other |
Number
|
UMath.Vec2
|
Vec2Object
|
The Vector or scalar to add |
(static) div(v, scalar) → {UMath.Vec2}
Returns a new Vector which is the division of the specified Vector by the specified scalar
(See UMath.Vec2#div
for a non-static version of this method)
- Source:
Parameters:
Name | Type | Description |
---|---|---|
v |
UMath.Vec2
|
Vec2Object
|
The Vector to divide |
scalar |
Number
|
The scalar to divide the Vector by |
(static) fromString(str) → {UMath.Vec2}
Returns a new Vector parsed from the specified String (of type "x,y", it removes parenthesis and extra spaces automatically)
(See UMath.Vec2#toString
to get a String from a Vector)
- Source:
Parameters:
Name | Type | Description |
---|---|---|
str |
String
|
The String to parse |
(static) mul(v, scalar) → {UMath.Vec2}
Returns a new Vector which is the multiplication of the specified Vector by the specified scalar
(See UMath.Vec2#mul
for a non-static version of this method)
- Source:
Parameters:
Name | Type | Description |
---|---|---|
v |
UMath.Vec2
|
Vec2Object
|
The Vector to multiply |
scalar |
Number
|
The scalar to multiply the Vector by |
(static) normalize(v) → {UMath.Vec2}
Returns a new Vector which is the specified one with a magnitude of 1
(See UMath.Vec2#normalize
for a non-static version of this method)
- Source:
Parameters:
Name | Type | Description |
---|---|---|
v |
UMath.Vec2
|
Vec2Object
|
The Vector to normalize |
(static) rotate(v, angle) → {UMath.Vec2}
Returns a new Vector equal to the specified Vector rotated by the specified angle
(See UMath.Vec2#rotate
for a non-static version of this method)
- Source:
Parameters:
Name | Type | Description |
---|---|---|
v |
UMath.Vec2
|
Vec2Object
|
The Vector to rotate |
angle |
Number
|
The angle to rotate the specified Vector by |
(static) sub(v, other) → {UMath.Vec2}
Returns a new Vector which is the subtraction of the two specified elements
(See UMath.Vec2#sub
for a non-static version of this method)
- Source:
Parameters:
Name | Type | Description |
---|---|---|
v |
UMath.Vec2
|
Vec2Object
|
The Vector to subtract from |
other |
Number
|
UMath.Vec2
|
Vec2Object
|
The Vector or scalar to subtract |