vector.length
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.
|
|||
Prints the length if a vector | |||
Code | <nowiki>
local vectorA = vector.new(6, 7, -8)
print("The length of my vector is:", vectorA.length(vectorA))
</nowiki>
|
||
Output | The length of my vector is: 12.20655... |
|
|||
An example of what the function looks like | |||
Code | <nowiki>
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)
</nowiki>
|
||
Output | The length of my vector is: 12.20655... |
vector.length Function | |
---|---|
Syntax vector.length(
Colon notation: self:length() | |
Returns | number length |
API | vector |
Source | CC:Tweaked (source) |
This article is issued from Computercraft. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.