Difference between revisions of "VectorA:normalize"

From ComputerCraft Wiki
Jump to: navigation, search
Line 1: Line 1:
−
Returns a normal vector with a length of 1
+
{{lowercase}}
−
 
+
{{Function
−
Code representation:
+
|name=vector:normalize
−
local a = vector.new(1, 2, 3)
+
|returns=[[float (type)|float]]
−
+
|api=vector
−
local len = a:length()
+
|addon=ComputerCraft
−
+
|desc=Returns a normalized representation of the vector.
−
local c = vector.new(a.x / len, a.y / len, a.z / len)
+
|examples=
−
--c.x = 0.26726124
+
{{Example
−
--c.y = 0.5345225
+
|desc=Normalizes a vector and prints the resulting vector.  Also prints the length to show it does equal 1.
−
  --c.z = 0.80178374
+
|code=local a = vector.new(1, 2, 3)  
−
 
+
−
Code example:
+
−
local a = vector.new(1, 2, 3)  
+
 
   
 
   
 
  local c = a:normalize()
 
  local c = a:normalize()
Line 24: 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]]

Revision as of 14:27, 23 February 2013


Grid Redstone.png  Function vector:normalize
Returns a normalized representation of the vector.
Syntax vector:normalize()
Returns float
Part of ComputerCraft
API vector

Examples

Grid paper.png  Example
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()

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



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 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