Difference between revisions of "VectorA:cross"

From ComputerCraft Wiki
Jump to: navigation, search
(Created page with "Returns the cross product of two vectors")
 
Line 1: Line 1:
Returns the cross product of two vectors
+
Returns a vector of the cross product of two vectors
 +
 
 +
Code representation:
 +
local a = vector.new(1, 2, 3)
 +
local b = vector.new(2, 1, 2)
 +
 +
local c = vector.new(
 +
  (a.y * b.z - a.z * b.y),
 +
  (a.z * b.x - z.x * b.z),
 +
  (a.x * b.y - a.y * b.x))
 +
 +
--c.x = 1
 +
--c.y = 4
 +
--c.z = -3
 +
 
 +
Code example:
 +
local a = vector.new(1, 2, 3)
 +
local b = vector.new(4, 5, 6)
 +
 +
local c = a:cross(b)
 +
 +
print(c.x)
 +
print(c.y)
 +
print(c.z)
 +
--(-3)
 +
--6
 +
--(-3)

Revision as of 10:12, 23 February 2013

Returns a vector of the cross product of two vectors

Code representation:

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

local c = vector.new(
 (a.y * b.z - a.z * b.y), 
 (a.z * b.x - z.x * b.z),
 (a.x * b.y - a.y * b.x))

--c.x = 1
--c.y = 4
--c.z = -3

Code example:

local a = vector.new(1, 2, 3)
local b = vector.new(4, 5, 6)

local c = a:cross(b)

print(c.x)
print(c.y)
print(c.z)
--(-3)
--6
--(-3)