Skip to content

float3

float3 describes a vector in 3D spaces. It contains functions for doing common vector operations.

Properties

float3 zero
A float3 with the magnitude of zero
float3 one
A float3 with a value of 1 on every axis
A float3 with a value of 1 on the Y axis
float3 down
A float3 with a value of -1 on the Y axis
float3 right
A float3 with a value of 1 on the X axis
float3 left
A float3 with a value of -1 on the X axis
float3 forward
A float3 with a value of 1 on the Z axis
float3 back
A float3 with a value of -1 on the Z axis
number magnitude
Returns the length of this vector
float3 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 float3
number y
The y-coordinate of the float3
number z
The z-coordinate of the float3

Functions

float3 float3.New(number x, number y, number z)
Constructs a new float3 using the given x, y, and z components.
number float3.Angle(float3 from, float3 to)
Calculates the angle between vectors from and. The angle returned is the angle of rotation from the first vector to the second, when treating these two vector inputs as directions. Note: The angle returned will always be between 0 and 180 degrees, because the method returns the smallest angle between the vectors. That is, it will never return a reflex angle.
  • from The vector from which the angular difference is measured.
  • to The vector to which the angular difference is measured.
float3 float3.ClampMagnitude(float3 value, number maxLength)
Returns a copy of value with its magnitude clamped to maxLength.
float3 float3.Cross(float3 a, float3 b)
Returns the cross product of the two vectors. The cross product of two vectors results in a third vector which is perpendicular to the two input vectors. The result's magnitude is equal to the magnitudes of the two inputs multiplied together and then multiplied by the sine of the angle between the inputs. You can determine the direction of the result vector using the "left hand rule".
number float3.Distance(float3 a, float3 b)
Returns the distance between a and b.
local other = float3.New(1,1,1)
local _self = float3.New(0,0,0)
local dist = float3.Distance(other, _self)
print("distance to other: " .. dist)
number float3.Dot(float3 a, float3 b)
Returns dot Product of two vectors. The dot product is a float value equal to the magnitudes of the two vectors multiplied together and then multiplied by the cosine of the angle between them.
float3 float3.Lerp(float3 a, float3 b, number t)
Linearly interpolates between two points. Interpolates between the points a and b by t. The parameter t is clamped to the range [0, 1]. This is most commonly used to find a point some fraction of the way along a line between two endpoints (e.g. to move an object gradually between those points). The value returned equals a + (b - a) * t (which can also be written a * (1-t) + b*t). When t = 0, float3.Lerp(a, b, t) returns a. When t = 1, float3.Lerp(a, b, t) returns b. When t = 0.5, float3.Lerp(a, b, t) returns the point midway between a and b.
  • a Start value, returned when t = 0.
  • b End value, returned when t = 1.
  • t Value used to interpolate between a and b.
float3 float3.Max(float3 a, float3 b)
Returns a vector that is made from the largest components of two vectors.
local a = float3.New(1,2,3)
local b = float3.New(3,2,1)
-- (3,2,3)
print(float3.Max(a,b))
float3 float3.Min(float3 a, float3 b)
Returns a vector that is made from the smallest components of two vectors.
float3 float3.MoveTowards(float3 current, float3 target, number maxDistanceDelta)
Calculate a position between the points specified by current and target, moving no farther than the distance specified by maxDistanceDelta.
  • current The position to move from.
  • target The position to move towards.
  • maxDistanceDelta Distance to move current per call.
float3 float3.Normalize(float3 value)
Makes this vector have a magnitude of 1. When normalized, a vector keeps the same direction but its length is 1.0.
float3 float3.Project(float3 a, float3 b)
Projects a vector onto another vector.
float3 float3.ProjectOnPlane(float3 value, float3 planeNormal)
Projects a vector onto a plane defined by a normal orthogonal to the plane.
  • value The location of the vector above the plane.
  • planeNormal The direction from the vector towards the plane.
float3 float3.Reflect(float3 inDirection, float3 inNormal)
Reflects a vector off the plane defined by a normal.
float3 float3.RotateTowards(float3 current, float3 target, number maxRadiansDelta, number maxMagnitudeDelta)
Rotates a vector current towards target.
  • current The vector being managed.
  • target The vector.
  • maxRadiansDelta The maximum angle in radians allowed for this rotation.
  • maxMagnitudeDelta The maximum allowed change in vector magnitude for this rotation.
float3 float3.Scale(float3 a, float3 b)
Multiplies two vectors component-wise. Every component in the result is a component of a multiplied by the same component of b.
float3 float3.Slerp(float3 a, float3 b, number t)
Spherically interpolates between two vectors. Interpolates between a and b by amount t. The parameter t is clamped to the range [0, 1].
float3 Mul(number value)
Multiplies self by a number, same as operator *.
local vector = float3.New(1,1,1)
-- same as result = vector * 2
local result = vector:Mul(2)
-- (2,2,2)
print(result)
float3 Div(number value)
Divides self by a number, same as operator /.
float3 Add(float3 value)
Adds other vector, same as operator +.
float3 Sub(float3 value)
Subtracts self from another, same as operator -.
number SqrMagnitude()
Returns the squared length of this vector.
boolean Equals(float3 other)
Returns true if two vectors are same, operator == returns true if two vectors are approximately equal.
float3 Clone()
Returns a deep copy of this vector.
number Magnitude()
Returns the length of this vector. The length of the vector is square root of (x*x+y*y+z*z).
void Set(number x, number y, number z)
Set x,y and z components of an existing float3.