vector.dot
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.
|
|||
Finds the dot product of two vectors | |||
Code | <nowiki>
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)
</nowiki>
|
||
Output | The dot product of my two vectors is: -5.6 |
|
|||
An example of what the function looks like | |||
Code | <nowiki>
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)
</nowiki>
|
||
Output | The dot product of my two vectors is: -5.6 |
vector.dot Function | |
---|---|
Syntax vector.dot(
Colon notation: self:dot(
| |
Returns | number dot product |
API | vector |
Source | CC:Tweaked (source) |
This article is issued from Computercraft. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.