Difference between revisions of "Vector (API)"

From ComputerCraft Wiki
Jump to: navigation, search
Line 1: Line 1:
{{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.
  
The vector API provides methods to create and manipulate vectors.  An introduction to vectors can be found on [[Wikipedia:Euclidean_vector|Wikipedia]].
+
Among other things, vectors can be useful to aid in creating navigation algorithms using GPS coordinates.
 +
 
 +
To transform GPS quickly into vector format, simply use:
 +
  local a = vector.new(gps.locate())
 +
 
 +
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;">
 
<table style="width: 100%; border: solid 1px black; margin: 2px; border-spacing: 0px;">

Revision as of 14:53, 23 February 2013

The vector API provides methods to create and manipulate vectors.

Among other things, vectors can be useful to aid in creating navigation algorithms using GPS coordinates.

To transform GPS quickly into vector format, simply use:

local a = vector.new(gps.locate())

An introduction to vectors can be found on Wikipedia.

Grid disk.png   Vector (API)

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