Difference between revisions of "VectorA:cross"

From ComputerCraft Wiki
Jump to: navigation, search
(Changing float to number)
 
(5 intermediate revisions by one other user not shown)
Line 3: Line 3:
 
|name=vector:cross
 
|name=vector:cross
 
|args=[[vector (API)|vector]] vect
 
|args=[[vector (API)|vector]] vect
|returns=[[vector (API)|vector]]
+
|returns={{type|number}}
 
|api=vector
 
|api=vector
 
|addon=ComputerCraft
 
|addon=ComputerCraft
Line 38: Line 38:
 
}}
 
}}
  
[[Category:API_Functions]]
+
It is important to note that a:cross(b) will not usually equal b:cross(a).
  
Returns a vector of the cross product of two vectors
+
More information about cross products can be found at [http://en.wikipedia.org/wiki/Cross_product]
  
More information on cross products can be found at [http://en.wikipedia.org/wiki/Cross_product]
+
[[Category:API_Functions]]
 
+
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)
+

Latest revision as of 13:20, 18 July 2013


Grid Redstone.png  Function vector:cross
Returns the vector which resulted in the cross product of the two vectors.
Syntax vector:cross(vector vect)
Returns number
Part of ComputerCraft
API vector

Examples

Grid paper.png  Example
Creates a cross product of two vectors and prints the resulting vector.
Code
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)



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


It is important to note that a:cross(b) will not usually equal b:cross(a).

More information about cross products can be found at [1]