Difference between revisions of "VectorA:sub"

From ComputerCraft Wiki
Jump to: navigation, search
 
(One intermediate revision by the same user not shown)
Line 6: Line 6:
 
|api=vector
 
|api=vector
 
|addon=ComputerCraft
 
|addon=ComputerCraft
|desc=Subtracts two vectors and returns the result
+
|desc=Subtracts a vector from the initial vector and returns the resulting vector.
 
|examples=
 
|examples=
 
{{Example
 
{{Example
|desc=Subtracts a vector from the initial vector and returns the resulting vector.
+
|desc=Subtracts two vectors and prints the resulting components.
 
|code=local a = vector.new(1, 2, 3)
 
|code=local a = vector.new(1, 2, 3)
 
  local b = vector.new(3, 2, 1)
 
  local b = vector.new(3, 2, 1)

Latest revision as of 12:01, 23 February 2013


Grid Redstone.png  Function vector:sub
Subtracts a vector from the initial vector and returns the resulting vector.
Syntax vector:sub(vector vect)
Returns vector
Part of ComputerCraft
API vector

Examples

Grid paper.png  Example
Subtracts two vectors and prints the resulting components.
Code
local a = vector.new(1, 2, 3)
local b = vector.new(3, 2, 1)

local c = a:sub(b)
--local c = (a - b)

print(c.x)
print(c.y)
print(c.z)
--(-2)
--0
--2