Difference between revisions of "Vector (API)"

From ComputerCraft Wiki
Jump to: navigation, search
m (Typo)
(the vector methods now use the correct self call syntax)
Line 21: Line 21:
 
|style="text-align: center; background: #EFEFEF" width="*"|Description
 
|style="text-align: center; background: #EFEFEF" width="*"|Description
 
|-
 
|-
|vectorA.add(vectorB)
+
|vectorA:add(vectorB)
 
|Adds vectorB to vectorA and returns the resulted vector.
 
|Adds vectorB to vectorA and returns the resulted vector.
 
|-
 
|-
|vectorA.sub(vectorB)
+
|vectorA:sub(vectorB)
 
|Subtracts vectorB to vectorA and returns the resulted vector.
 
|Subtracts vectorB to vectorA and returns the resulted vector.
 
|-
 
|-
|vectorA.mul(vectorB)
+
|vectorA:mul(vectorB)
 
|Multiplies vectorB with vectorA and returns the resulted vector.
 
|Multiplies vectorB with vectorA and returns the resulted vector.
 
|-
 
|-
|vectorA.dot(vectorB)
+
|vectorA:dot(vectorB)
 
|Returns the dot product of vectorA and vectorB.
 
|Returns the dot product of vectorA and vectorB.
 
|-
 
|-
|vectorA.cross(vectorB)
+
|vectorA:cross(vectorB)
 
|Returns the vector which resulted in the cross product of vectorA and vectorB.
 
|Returns the vector which resulted in the cross product of vectorA and vectorB.
 
|-
 
|-
|vectorA.length()
+
|vectorA:length()
 
|Returns the vector's length.
 
|Returns the vector's length.
 
|-
 
|-
|vectorA.normalize()
+
|vectorA:normalize()
 
|Normalizes the vector and returns the result as a new vector.
 
|Normalizes the vector and returns the result as a new vector.
 
|-
 
|-
|vectorA.round()
+
|vectorA:round()
 
|Rounds the vector coordinates to the nearest integers and returns the result as a new vector.
 
|Rounds the vector coordinates to the nearest integers and returns the result as a new vector.
 
|-
 
|-
|vectorA.tostring()
+
|vectorA:tostring()
 
|Returns a string representation of the vector in the form of "x,y,z".
 
|Returns a string representation of the vector in the form of "x,y,z".
 
|}
 
|}
  
 
[[Category:APIs]]
 
[[Category:APIs]]

Revision as of 09:34, 21 April 2012

The vector API provides methods to create and manipulate vectors.


Static methods
Method name Description
vector.new(x, y, z) Creates a vector.

@param x, y, z the vector coordinates
@return the created vector


Object methods
Method name Description
vectorA:add(vectorB) Adds vectorB to vectorA and returns the resulted vector.
vectorA:sub(vectorB) Subtracts vectorB to vectorA and returns the resulted vector.
vectorA:mul(vectorB) Multiplies vectorB with vectorA and returns the resulted vector.
vectorA:dot(vectorB) Returns the dot product of vectorA and vectorB.
vectorA:cross(vectorB) Returns the vector which resulted in the cross product of vectorA and vectorB.
vectorA:length() Returns the vector's length.
vectorA:normalize() Normalizes the vector and returns the result as a new vector.
vectorA:round() Rounds the vector coordinates to the nearest integers and returns the result as a new vector.
vectorA:tostring() Returns a string representation of the vector in the form of "x,y,z".