Difference between revisions of "VectorA:dot"
From ComputerCraft Wiki
| Line 1: | Line 1: | ||
| − | Returns the dot product of two vectors | + | {{lowercase}} |
| − | + | {{Function | |
| − | + | |name=vector:dot | |
| − | + | |args=[[vector (API)|vector]] vect | |
| − | + | |returns=[[vector (API)|vector]] | |
| − | + | |api=vector | |
| − | + | |addon=ComputerCraft | |
| − | local a = vector.new(1, 2, 3) | + | |desc=Returns the dot product of two vectors. |
| + | |examples= | ||
| + | {{Example | ||
| + | |desc=Creates a dot 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:dot(b) | ||
| + | |||
| + | print(c) | ||
| + | --32 | ||
| + | }} | ||
| + | {{Example | ||
| + | |desc=Code to recreate the function. Gives insight into what the function does. | ||
| + | |code=local a = vector.new(1, 2, 3) | ||
local b = vector.new(-1, 2, 5) | local b = vector.new(-1, 2, 5) | ||
local c = ((a.x * b.x) + (a.y * b.y) + (a.z * b.z)) | local c = ((a.x * b.x) + (a.y * b.y) + (a.z * b.z)) | ||
--c = 18 | --c = 18 | ||
| + | }} | ||
| + | }} | ||
| + | In the case of dot products, a:dot(b) will equal b:dot(a). | ||
| − | + | More information about dot products can be found at [http://en.wikipedia.org/wiki/Dot_product] | |
| − | + | ||
| − | + | [[Category:API_Functions]] | |
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
Latest revision as of 14:18, 23 February 2013
| Returns the dot product of two vectors. | |
| Syntax | vector:dot(vector vect) |
| Returns | vector |
| Part of | ComputerCraft |
| API | vector |
Examples
| Creates a dot 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:dot(b) print(c) --32 |
In the case of dot products, a:dot(b) will equal b:dot(a).
More information about dot products can be found at [1]