abstract hxmath.math.Vector2(Vector2Default) from Vector2Default to Vector2Default
Available on all platforms
A 2D vector.
Class Fields
function equals(a:Vector2, b:Vector2):Bool
Test element-wise equality between two vectors. False if one of the inputs is null and the other is not.
a | |
b | |
returns | ai == bi |
function fromArray(rawData:Array<Float>):Vector2
Construct a Vector2 from an array.
rawData | The input array. |
returns | The constructed structure. |
function fromPolar(angle:Float, radius:Float):Vector2
Create a new Vector2 from polar coordinates. Example angle-to-vector direction conversions: 0 radians -> +X axis (1/2)pi radians -> +Y axis pi radians -> -X axis (3/2)pi radians -> -Y axis
angle | The angle of the vector (counter-clockwise from the +X axis) in radians. |
radius | The length of the vector. |
returns | The vector. |
function lerp(a:Vector2, b:Vector2, t:Float):Vector2
Linear interpolation between two vectors.
a | The value at t = 0 |
b | The value at t = 1 |
t | A number in the range [0, 1] |
returns | The interpolated value |
function notEquals(a:Vector2, b:Vector2):Bool
Test inequality between two vectors.
a | |
b | |
returns | !(ai == bi) |
Instance Fields
function addWith(a:Vector2):Vector2
Add a vector in place. Note: += operator on Haxe abstracts does not behave this way (a new object is returned).
a | |
returns | selfi += ai |
function angleWith(b:Vector2):Float
Find the arccosine of the angle between two vectors.
b | The other vector. |
returns | The arccosine angle between this vector and the other in radians. |
function applyScalarFunc(func:Float ->Float):Vector2
Apply a scalar function to each element.
func | The function to apply. |
returns | The modified object. |
function copyTo(other:Vector2):Void
Copy the contents of this structure to another.
other | The target structure. |
function getArrayElement(i:Int):Float
Get an element by position.
i | The element index. |
returns | The element. |
function setArrayElement(i:Int, value:Float):Float
Set an element by position.
i | The element index. |
value | The new value. |
returns | The updated element. |
function signedAngleWith(b:Vector2):Float
Find the signed angle between two vectors.
If the other vector is in the left halfspace of this vector (e.g. the shortest angle to align this vector with the other is ccw) then the result is positive.
If the other vector is in the right halfspace of this vector (e.g. the shortest angle to align this vector with the other is cw) then the result is negative.
b | The other vector. |
returns | The signed angle between this vector and the other in radians. |
function subtractWith(a:Vector2):Vector2
Subtract a vector in place. Note: -= operator on Haxe abstracts does not behave this way (a new object is returned).
a | |
returns | selfi -= ai |