vector.cross

From ComputerCraft
Jump to: navigation, search

vector.cross
Function
Syntax
vector.cross()
Colon notation: self:cross()

Returns table cross product
API vector
Source CC:Tweaked (source)

Given two vectors, self and object, this function will output their cross product. If the arguments do not follow Computercraft's vector style (a table with the contents: x, y, and z) the function could output undesired results.

ExampleExampleFind the cross product
Finds the cross product of two vectors
Code
local vectorA = vector.new(6, 7, -8)
local vectorB = vector.new(2, 3.2, 5)
local crossProduct = vector.cross(vectorA, vectorB)
print("The cross product of my two vectors is:", crossProduct)
Output The cross product of my two vectors is: 60.6 -46 5.2
ExampleExampleBehind the scenes
An example of what the function looks like
Code
local vectorA = vector.new(6, 7, -8)
local vectorB = vector.new(2, 3.2, 5)
local crossProduct = vector.new(
    (vectorA.y * vectorB.z - vectorA.z * vectorB.y),
    (vectorA.z * vectorB.x - vectorA.x * vectorB.z),
    (vectorA.x * vectorB.y - vectorA.y * vectorB.x))
print("The cross product of my two vectors is:", crossProduct)
Output The cross product of my two vectors is: 60.6 -46 5.2