Difference between revisions of "VectorA:normalize"
From ComputerCraft Wiki
(Created page with "Returns a normal vector with a length of 1 Code representation: local a = vector.new(1, 2, 3) local len = a:length() local c = vector.new(a.x / len, a.y / len, a.z / l...") |
(Changing number to number) |
||
(2 intermediate revisions by one other user not shown) | |||
Line 1: | Line 1: | ||
− | Returns a | + | {{lowercase}} |
− | + | {{Function | |
− | + | |name=vector:normalize | |
− | local a = vector.new(1, 2, 3) | + | |returns={{type|number}} |
+ | |api=vector | ||
+ | |addon=ComputerCraft | ||
+ | |desc=Returns a normalized representation of the vector. | ||
+ | |examples= | ||
+ | {{Example | ||
+ | |desc=Normalizes a vector and prints the resulting vector. Also prints the length to show it does equal 1. | ||
+ | |code=local a = vector.new(1, 2, 3) | ||
− | + | local c = a:normalize() | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | local c = a: | + | |
print(c.x) | print(c.x) | ||
Line 23: | Line 21: | ||
--0.80178374 | --0.80178374 | ||
--1 | --1 | ||
+ | }} | ||
+ | {{Example | ||
+ | |desc=Code to recreate the function. Gives insight into what the function does. | ||
+ | |code=local a = vector.new(1, 2, 3) | ||
+ | |||
+ | local len = a:length() | ||
+ | |||
+ | local c = vector.new(a.x / len, a.y / len, a.z / len) | ||
+ | --c.x = 0.26726124 | ||
+ | --c.y = 0.5345225 | ||
+ | --c.z = 0.80178374 | ||
+ | }} | ||
+ | }} | ||
+ | |||
+ | [[Category:API_Functions]] |
Latest revision as of 14:50, 18 July 2013
Function vector:normalize | |
Returns a normalized representation of the vector. | |
Syntax | vector:normalize() |
Returns | number |
Part of | ComputerCraft |
API | vector |
Examples