Number3

A Number3 contains 3 number values (X, Y & Z). It can represent different things in 3D space (points, vectors, forces).

Constructors

Number3 ( number x, number y, number z )

Creates a Number3 with values x, y and z.

local myNumber3 = Number3(1, 2, 3)

Functions

number Angle ( Number3 vector )
number Angle ( number vectorX, number vectorY, number vectorZ )

Returns the angle in radians between this and given vector.

Returns a copy of the Number3.

local n1 = Number3(1, 0, 0)
local n2 = n1 -- n2 is not a copy but a direct reference to n1
n2.X = 10
print(n1.X) -- now n1.X == 10

-- using Copy:
local n1 = Number3(1, 0, 0)
local n2 = n1:Copy() -- n2 is a copy of n1, they're not the same Number3
n2.X = 10
print(n1.X) -- n1.X is still 1

Returns the cross product of both Number3s.

local n1 = Number3(1, 0, 0)
local n2 = Number3(1, 0, 0)
local n3 = n1:Cross(n2)

Returns the dot product of both Number3s.

local n1 = Number3(1, 0, 0)
local n2 = Number3(1, 0, 0)
local dot = n1:Dot(n2)
nil Lerp ( Number3 from, Number3 to, number ratio )

Sets this Number3 to the linear interpolation between two given Number3 at a given ratio.

Normalizes the Number3 so that its magnitude(/reference/number3#property-length) becomes 1.0, and return it.

local someNumber3 = Number3(10,0,0)
someNumber3:Normalize()
-- someNumber3 == 1 now

-- NOTE: this also achieves normalization:
someNumber3.Length = 1.0
nil Rotate ( Number3 eulerAnglesXYZ )
nil Rotate ( number eulerAngleX, number eulerAngleY, number eulerAngleZ )
nil Rotate ( Rotation rotation )

Rotates the Number3 using euler angles in parameters (in radians).

local someNumber3 = Number3(0,0,1)
local pi = 3.1415
someNumber3:Rotate(Number3(0,pi,0))
-- someNumber3 == Number3(0,0,-1), after a PI rotation around Y axis (180°)
nil Set ( Number3 xyz )
nil Set ( number x, number y, number z )

Sets this Number3's components to the given values.

Properties

Magnitude of the Number3.
Technically, the square root of the sum of X, Y & Z components.

number3 = Number3(3,4,12)
print(number3.Length) -- prints 13
-- sqrt(3*3 + 4*4 + 12*12) = 13

Reading Number3.SquaredLength is faster than reading Number3.Length.
This is the main reason why this attribute is exposed.
It can be used when comparing distances.

-- compare distances between objects
local d2 = o1.Position - o2.Position
local d3 = o1.Position - o3.Position

if d2.SquaredLength < d3.SquaredLength then
  print("o1 is closer to o2")
else
  print("o1 is closer to o3")
end
-- Using Length instead of SquaredLength would give the same results,
-- but it would have to internally compute 2 square roots for nothing.

X value of the Number3.

myNumber3.X = 42
print(myNumber3.X)

Y value of the Number3.

myNumber3.Y = 42
print(myNumber3.Y)

Z value of the Number3.

myNumber3.Z = 42
print(myNumber3.Z)