VectorA:normalize

From ComputerCraft Wiki
Revision as of 11:03, 23 February 2013 by MafiaMoe (Talk | contribs) (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...")

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

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 / len) 
--c.x = 0.26726124
--c.y = 0.5345225
--c.z = 0.80178374

Code example:

local a = vector.new(1, 2, 3) 
local c = a:cross(b)

print(c.x)
print(c.y)
print(c.z)
print(c:length())
--0.26726124
--0.5345225
--0.80178374
--1