# 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

#### float3 up¶

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)¶

ReturnsThe angle in degrees between the two vectors.
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`.
 ```1 2 3 4``` ``````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)¶

ReturnsInterpolated value, equals to a + (b - a) * 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.
 ```1 2 3 4``` ``````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)¶

ReturnsThe location of the vector on the plane.
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)¶

ReturnsThe location that RotateTowards generates.
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)¶

ReturnsSelf.
Multiplies self by a number. Mul will modify the value of self. Instead, apply operator `*` to create a new float3 value without self modification.
• `value` A number.
 ```1 2 3 4 5 6 7 8``` ``````local a = float3.New(1,1,1) a:Mul(2) print(tostring(a)) -- output: [2,2,2] local b = float3.New(3, 5, 7) local c = b * 2 print(tostring(b)) -- output: [3,5,7] print(tostring(c)) -- output: [6,10,14] ``````

In this example, `Mul` modifies the value of `a` to [2,2,2], while `b*2` creates a new float3 without modifying `b`.

#### float3 Div(number value)¶

ReturnsSelf.
Divides self by a number. Div will modify the value of self. Instead, apply operator `/` to create a new float3 value without self modification.
• `value` A number.

ReturnsSelf.
Adds a float3 to self. `Add` will modify the value of self. Instead, apply operator `+` to create a new float3 value without modification.
• `value` A float3 value.
 ``` 1 2 3 4 5 6 7 8 9 10``` ``````local a = float3.New(1, 2, 3) a:Add(float3.New(4, 5, 6)) print(tostring(a)) -- output: [5,7,9] local b = float3.New(8, 10, 12) local c = float3.New(9, 11, 13) local d = b+c print(tostring(b)) -- output: [8,10,12] print(tostring(c)) -- output: [9,11,13] print(tostring(d)) -- output: [17,21,25] ``````

In this example, function `Add` modifies the value of a to [5,7,9], while `b+c` creates a new float3 without modification.

#### float3 Sub(float3 value)¶

ReturnsSelf.
Subtracts a float3 from self. `Sub` will modify the value of self. Instead, apply operator `-` to create a new float3 value without modification.
• `value` A float3.

#### 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.