Difference between revisions of "Vector (API)"

From ComputerCraft Wiki
Jump to: navigation, search
m (Urfg I can't match page names.)
(Changed to match other function pages)
Line 1: Line 1:
{{NeedsWork|Doesn't use any of the method or example templates. Can we get this rectified? ''[[User:AfterLifeLochie|AfterLifeLochie]] 02:38, 29 November 2012 (MSK)''}}
+
{{NeedsWork|Needs function pages, some parameters missing types ''[[User:Pokepal101|Pokepal101]] 02:42, 29 December 2012 (MSK)''}}
  
 
The vector API provides methods to create and manipulate vectors.  An introduction to vectors can be found on [[Wikipedia:Euclidean_vector|Wikipedia]].
 
The vector API provides methods to create and manipulate vectors.  An introduction to vectors can be found on [[Wikipedia:Euclidean_vector|Wikipedia]].
  
 +
<table style="width: 100%; border: solid 1px black; margin: 2px; border-spacing: 0px;">
 +
<tr><td colspan="2" style="font-weight: bold; font-size: large; padding-bottom: .3em; border-bottom: solid #C9C9C9 1px; background: #D3FFC2; line-height:28px;">
 +
&nbsp;&nbsp;
 +
Vector (API)
 +
</td></tr>
 +
<tr style="background-color: #FFFFFF;"><td style="border-top: solid #C9C9C9 1px; padding: .4em;">[[vector.new]](x, y, z)</td>
 +
<td style="border-top: solid #C9C9C9 1px; padding: .4em;">Creates a vector.</td></tr>
  
{| border="1" cellpadding="2" cellspacing="0"
+
<tr style="background-color: #FFFFFF;"><td style="border-top: solid #C9C9C9 1px; padding: .4em;">[[vectorA:add]]([[vector]] vectorB)</td>
!colspan="2" style="text-align: center; background: #DDDDDD"|Static methods
+
<td style="border-top: solid #C9C9C9 1px; padding: .4em;">Adds vectorB to vectorA and returns the resulted vector. Can also be used by writing vectorA + vectorB.</td></tr>
|-
+
|style="text-align: center; background: #EFEFEF" width="200px"|Method name
+
|style="text-align: center; background: #EFEFEF" width="*"|Description
+
|-
+
|vector.new(x, y, z)
+
|Creates a vector.<br />
+
''@param'' '''x, y, z''' the vector coordinates<br />
+
''@return'' the created vector
+
|}
+
  
 +
<tr style="background-color: #FFFFFF;"><td style="border-top: solid #C9C9C9 1px; padding: .4em;">[[vectorA:sub]]([[vector]] vectorB)</td>
 +
<td style="border-top: solid #C9C9C9 1px; padding: .4em;">Subtracts vectorB from vectorA and returns the resulted vector. Can also be used by writing vectorA - vectorB.</td></tr>
  
{| border="1" cellpadding="2" cellspacing="0"
+
<tr style="background-color: #FFFFFF;"><td style="border-top: solid #C9C9C9 1px; padding: .4em;">[[vectorA:mul]](n)</td>
!colspan="2" style="text-align: center; background: #DDDDDD"|Object methods
+
<td style="border-top: solid #C9C9C9 1px; padding: .4em;">Scalar multiplies vectorA with n and returns the resulted vector. Can also be used by writing vectorA * n.</td></tr>
|-
+
 
|style="text-align: center; background: #EFEFEF" width="200px"|Method name
+
<tr style="background-color: #FFFFFF;"><td style="border-top: solid #C9C9C9 1px; padding: .4em;">[[vectorA:dot]]([[vector]] vectorB)</td>
|style="text-align: center; background: #EFEFEF" width="*"|Description
+
<td style="border-top: solid #C9C9C9 1px; padding: .4em;">Returns the dot product of vectorA and vectorB.</td></tr>
|-
+
 
|vectorA:add(vectorB)
+
<tr style="background-color: #FFFFFF;"><td style="border-top: solid #C9C9C9 1px; padding: .4em;">[[vectorA:cross]]([[vector]] vectorB)</td>
|Adds vectorB to vectorA and returns the resulted vector. Can also be used by writing vectorA + vectorB.
+
<td style="border-top: solid #C9C9C9 1px; padding: .4em;">Returns the vector which resulted in the cross product of vectorA and vectorB.</td></tr>
|-
+
 
|vectorA:sub(vectorB)
+
<tr style="background-color: #FFFFFF;"><td style="border-top: solid #C9C9C9 1px; padding: .4em;">[[vectorA:length]]()</td>
|Subtracts vectorB to vectorA and returns the resulted vector. Can also be used by writing vectorA - vectorB.
+
<td style="border-top: solid #C9C9C9 1px; padding: .4em;">Returns the vector's length.</td></tr>
|-
+
 
|vectorA:mul(n)
+
<tr style="background-color: #FFFFFF;"><td style="border-top: solid #C9C9C9 1px; padding: .4em;">[[vectorA:normalize]]()</td>
|Scalar multiplies vectorA with n and returns the resulted vector. Can also be used by writing vectorA * n.
+
<td style="border-top: solid #C9C9C9 1px; padding: .4em;">Normalizes the vector and returns the result as a new vector.</td></tr>
|-
+
 
|vectorA:dot(vectorB)
+
<tr style="background-color: #FFFFFF;"><td style="border-top: solid #C9C9C9 1px; padding: .4em;">[[vectorA:round]]()</td>
|Returns the dot product of vectorA and vectorB.
+
<td style="border-top: solid #C9C9C9 1px; padding: .4em;">Rounds the vector coordinates to the nearest integers and returns the result as a new vector.</td></tr>
|-
+
 
|vectorA:cross(vectorB)
+
<tr style="background-color: #FFFFFF;"><td style="border-top: solid #C9C9C9 1px; padding: .4em;">[[vectorA:tostring]]()</td>
|Returns the vector which resulted in the cross product of vectorA and vectorB.
+
<td style="border-top: solid #C9C9C9 1px; padding: .4em;">Returns a string representation of the vector in the form of "x,y,z".</td></tr>
|-
+
 
|vectorA:length()
+
<tr style="background-color: #E8E8E8;"><td style="border-top: solid #C9C9C9 1px; padding: .4em;"></td>
|Returns the vector's length.
+
<td style="border-top: solid #C9C9C9 1px; padding: .4em;"></td></tr>
|-
+
</table>
|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".
+
|}
+
  
 
[[Category:APIs]]
 
[[Category:APIs]]

Revision as of 22:42, 28 December 2012

This page needs some serious TLC, stat!
Please help us by cleaning it, fixing it up, or sparing it some love.
(Reason: Needs function pages, some parameters missing types Pokepal101 02:42, 29 December 2012 (MSK))

The vector API provides methods to create and manipulate vectors. An introduction to vectors can be found on Wikipedia.

   Vector (API)

vector.new(x, y, z) Creates a vector.
vectorA:add(vector vectorB) Adds vectorB to vectorA and returns the resulted vector. Can also be used by writing vectorA + vectorB.
vectorA:sub(vector vectorB) Subtracts vectorB from vectorA and returns the resulted vector. Can also be used by writing vectorA - vectorB.
vectorA:mul(n) Scalar multiplies vectorA with n and returns the resulted vector. Can also be used by writing vectorA * n.
vectorA:dot(vector vectorB) Returns the dot product of vectorA and vectorB.
vectorA:cross(vector 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".