float2¶
float2
describes a vector in 2D spaces.
It contains functions for doing common vector operations.Properties¶
float2 zero
A float2 with the magnitude of zero
float2 one
A float2 with a value of 1 on every axis
float2 up
A float2 with a value of 1 on the Y axis
float2 down
A float2 with a value of -1 on the Y axis
float2 right
A float2 with a value of 1 on the X axis
float2 left
A float2 with a value of -1 on the X axis
number magnitude
Returns the length of this vector
float2 normalized
Returns this vector with a magnitude of 1
number sqrMagnitude
Returns the squared length of this vector
number x
The x-coordinate of the float2
number y
The y-coordinate of the float2
Functions¶
Constructs a new float2 using the given
x
, and y
components.
Gets the unsigned angle in degrees between
from
and to
.
The angle returned is the unsigned angle between the two vectors.
from
The vector from which the angular difference is measured.to
The vector to which the angular difference is measured.
Returns a copy of
value
with its magnitude clamped to maxLength
.
Returns the distance between
a
and b
.
local other = float2.New(1,1)
local _self = float2.New(0,0)
local dist = float2.Distance(other, _self)
print("distance to other: " .. dist)
Returns dot Product of two vectors.
Linearly interpolates between two points.
Interpolates between the points
a
and b
by t
. The parameter t
is clamped to the range [0, 1].
When t
= 0, returns a
.
When t
= 1, returns b
.
When t
= 0.5, returns the midpoint of between a
and b
.
a
Start value, returned when t = 0.b
End value, returned when t = 1.
Linearly interpolates between vectors
a
and b
by t
.
When t
= 0, returns a
.
When t
= 1, returns b
.
When t
= 0.5, returns the midpoint of between a
and b
.
Returns a vector that is made from the largest components of two vectors.
local a = float2.New(1,2)
local b = float2.New(3,1)
-- (3,2)
print(float2.Max(a,b))
Returns a vector that is made from the smallest components of two vectors.
Moves a point
current
towards target
.
current
The position to move from.target
The position to move towards.maxDistanceDelta
Distance to movecurrent per call.
Makes vector have a magnitude of 1.
When normalized, a vector keeps the same direction but its length is 1.0.
Reflects a vector off the plane defined by a normal.
Multiplies two vectors component-wise.
Every component in the result is a component of
a
multiplied by the same component of b
.
float2 Mul(number value)
Multiplies self by a number, same as operator
*
.
local vector = float2.New(1,1)
-- same as result = vector * 2
local result = vector:Mul(2)
-- (2,2)
print(result)
float2 Div(number value)
Divides self by a number, same as operator
/
.
Adds other vector, same as operator
+
.
Subtracts self from another.
number SqrMagnitude()
Returns the squared length of this vector.
float2 Clone()
Returns a deep copy of this vector.
float2 Magnitude()
Returns the length of this vector.
The length of the vector is square root of
(x*x+y*y)
.
void Set(number x, number y)
Set
x
and y
components of an existing float2.
float2 SetNormalize()
Makes this vector have a magnitude of 1.