vectorA:length

From ComputerCraft Wiki
Revision as of 13:25, 18 July 2013 by Cranium (Talk | contribs) (corrected link)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search


Grid Redstone.png  Function vector:length
Returns the length of the vector.
Syntax vector:length()
Returns number
Part of ComputerCraft
API vector

Examples

Grid paper.png  Example
Takest the length of the vector and prints it.
Code
local a = vector.new(2, 5, 9)
 
local c = a:length()

print(c)
--10.488089



Grid paper.png  Example
Code to recreate the function. Gives insight into what the function does.
Code
local a = vector.new(1, 2, 3)

local c = math.sqrt(a.x^2 + a.y^2 + a.z^2)

--c = 3.7416575