Difference between revisions of "FSOSS 2010/processing.js/vectors"

From CDOT Wiki
Jump to: navigation, search
Line 8: Line 8:
  
 
<b>Operations</b><br />
 
<b>Operations</b><br />
<b>Add</b> two vectors by adding their components [3, 3] + [1, 2] = [4, 5]<br />
+
<br />
<b>Scale</b> a vector by multiplying by a scalar value [1,3] * 2 = [2, 6]<br />
+
<b>Addition</b>
 +
<ul>
 +
  <li>Add two vectors geometrically by adding head to tail</li>
 +
  <li>Add two vectors algebraically by adding their components [3, 3] + [1, 2] = [4, 5]</li>
 +
  <li>PVector.add(PVector)</li>
 +
</ul>
 +
 
 +
<b>Scale</b>
 +
<ul>
 +
<li>Scale a vector geometrically by stretching or shrinking</li>
 +
<li>Scale a vector algebraically by multiplying all components by scalar [1,3] * 2 = [2, 6]</li>
 +
<li>PVector.mult(float)</li>
 +
</ul>

Revision as of 22:09, 27 October 2010

Vectors

  • Object with a direction and magnitude (length)
  • Typically represented using coordinates for simplicity
  • Used for storing position, velocity, acceleration, etc.
  • Processing has a built-in PVector object for 2D and 3D

Operations

Addition

  • Add two vectors geometrically by adding head to tail
  • Add two vectors algebraically by adding their components [3, 3] + [1, 2] = [4, 5]
  • PVector.add(PVector)

Scale

  • Scale a vector geometrically by stretching or shrinking
  • Scale a vector algebraically by multiplying all components by scalar [1,3] * 2 = [2, 6]
  • PVector.mult(float)