Difference between revisions of "VectorA:dot"

From ComputerCraft Wiki
Jump to: navigation, search
(Created page with "Returns the dot product of two vectors A dot product can be represented by multiplying the corresponding values together and then summing the results. More information on do...")
 
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
Returns the dot product of two vectors
+
{{lowercase}}
 
+
{{Function
A dot product can be represented by multiplying the corresponding values together and then summing the results.
+
|name=vector:dot
 
+
|args=[[vector (API)|vector]] vect
More information on dot products can be found at [http://en.wikipedia.org/wiki/Dot_product]
+
|returns=[[vector (API)|vector]]
 
+
|api=vector
Code representation:
+
|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).
  
Code example:
+
More information about dot products can be found at [http://en.wikipedia.org/wiki/Dot_product]
local a = vector.new(1, 2, 3)
+
 
local b = vector.new(4, 5, 6)
+
[[Category:API_Functions]]
+
local c = a:dot(b)
+
+
print(c)
+
--32
+

Latest revision as of 14:18, 23 February 2013


Grid Redstone.png  Function vector:dot
Returns the dot product of two vectors.
Syntax vector:dot(vector vect)
Returns vector
Part of ComputerCraft
API vector

Examples

Grid paper.png  Example
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



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(-1, 2, 5)

local c = ((a.x * b.x) + (a.y * b.y) + (a.z * b.z))
--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 [1]