vector.dot

From ComputerCraft
Jump to: navigation, search

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

Returns number dot product
API vector
Source CC:Tweaked (source)

Given two vectors, self and object, this function will multiply and add the components of object and self and output their dot product. If either argument does not follow Computercraft's vector style (a table with the contents: x, y, and z) the function will error.

ExampleExampleFind the dot product
Finds the dot product of two vectors
Code
local vectorA = vector.new(6, 7, -8)
local vectorB = vector.new(2, 3.2, 5)
local dotProduct = vector.dot(vectorA, vectorB) --12+22.4+(-40)
print("The dot product of my two vectors is:", dotProduct)
Output The dot product of my two vectors is: -5.6
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 dotProduct = (vectorA.x*vectorB.x)+(vectorA.y*vectorB.y)+(vectorA.z*vectorB.z)
print("The dot product of my two vectors is:", dotProduct)
Output The dot product of my two vectors is: -5.6