vector.length

From ComputerCraft
Jump to: navigation, search

vector.length
Function
Syntax
vector.length()
Colon notation: self:length()

Returns number length
API vector
Source CC:Tweaked (source)

Given a vector, self, this function will square and add the components of self to define the length of the vector. If self does not follow Computercraft's vector style (a table with the contents: x, y, and z) the function will error.

ExampleExampleFind a vectors length
Prints the length if a vector
Code
local vectorA = vector.new(6, 7, -8)
print("The length of my vector is:", vectorA.length(vectorA))
Output The length of my vector is: 12.20655...
ExampleExampleBehind the scenes
An example of what the function looks like
Code
local vectorA = vector.new(6, 7, -8)
local length = (vectorA.x*vectorA.x)+(vectorA.y*vectorA.y)+(vectorA.z*vectorA.z)
print("The length of my vector is:", length)
Output The length of my vector is: 12.20655...