float3describes a vector in 3D spaces. It contains functions for doing common vector operations.
A float3 with the magnitude of zero
A float3 with a value of 1 on every axis
A float3 with a value of 1 on the Y axis
A float3 with a value of -1 on the Y axis
A float3 with a value of 1 on the X axis
A float3 with a value of -1 on the X axis
A float3 with a value of 1 on the Z axis
A float3 with a value of -1 on the Z axis
Returns the length of this vector
Returns this vector with a magnitude of 1
Returns the squared length of this vector
The x-coordinate of the float3
The y-coordinate of the float3
The z-coordinate of the float3
float3 float3.New(number x, number y, number z)
Constructs a new float3 using the given x, y, and z components.
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.
fromThe vector from which the angular difference is measured.
toThe vector to which the angular difference is measured.
Returns a copy of
valuewith its magnitude clamped to
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".
Returns the distance between
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)
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.
Linearly interpolates between two points. Interpolates between the points
t. The parameter
tis 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.
aStart value, returned when t = 0.
bEnd value, returned when t = 1.
tValue used to interpolate between a and 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))
Returns a vector that is made from the smallest components of two vectors.
Calculate a position between the points specified by
target, moving no farther than the distance specified by
currentThe position to move from.
targetThe position to move towards.
maxDistanceDeltaDistance to move
Makes this vector have a magnitude of 1. When normalized, a vector keeps the same direction but its length is 1.0.
Projects a vector onto another vector.
Projects a vector onto a plane defined by a normal orthogonal to the plane.
valueThe location of the vector above the plane.
planeNormalThe direction from the vector towards the plane.
Reflects a vector off the plane defined by a normal.
float3 float3.RotateTowards(float3 current, float3 target, number maxRadiansDelta, number maxMagnitudeDelta)
Rotates a vector
currentThe vector being managed.
maxRadiansDeltaThe maximum angle in radians allowed for this rotation.
maxMagnitudeDeltaThe maximum allowed change in vector magnitude for this rotation.
Multiplies two vectors component-wise. Every component in the result is a component of
amultiplied by the same component of
Spherically interpolates between two vectors. Interpolates between
t. The parameter
tis 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
Adds other vector, same as operator
Subtracts self from another, same as operator
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.
Returns a deep copy of this vector.
Returns the length of this vector. The length of the vector is square root of
void Set(number x, number y, number z)
zcomponents of an existing float3.