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

From CDOT Wiki
Jump to: navigation, search
 
(One intermediate revision by the same user not shown)
Line 11: Line 11:
 
<b>Addition</b>
 
<b>Addition</b>
 
<ul>
 
<ul>
   <li>Add two vectors geometrically by adding head to tail</li>
+
   <li>Graphically -> add head to tail</li>
   <li>Add two vectors algebraically by adding their components [3, 3] + [1, 2] = [4, 5]</li>
+
   <li>Algebraically -> add components [3, 3] + [1, 2] = [4, 5]</li>
   <li>PVector.add(PVector)</li>
+
   <li>PVector.add(v1, v2);</li>
 +
  <li>vec.add(v);</li>
 +
</ul>
 +
 
 +
<b>Subtraction</b>
 +
<ul>
 +
  <li>Graphically -> flip the direction of one vector, then add</li>
 +
  <li>Algebraically -> subtract components [3, 3] - [1, 2] = [2, 1]</li>
 +
  <li>PVector.sub(v1, v2);</li>
 +
  <li>vec.sub(v);</li>
 
</ul>
 
</ul>
  
 
<b>Scale</b>
 
<b>Scale</b>
 
<ul>
 
<ul>
  <li>Scale a vector geometrically by stretching or shrinking</li>
+
  <li>Graphically -> stretch or shrink</li>
  <li>Scale a vector algebraically by multiplying all components by scalar [1,3] * 2 = [2, 6]</li>
+
  <li>Algebraically -> multiply components by scalar [1,3] * 2 = [2, 6]</li>
  <li>PVector.mult(float)</li>
+
  <li>PVector.mult(float);</li>
 +
</ul>
 +
 
 +
<b>Calculate Magnitude</b>
 +
<ul>
 +
  <li>Graphically -> measure length</li>
 +
  <li>Algebraically -> use Pythagorean theorem</li>
 +
  <li>PVector.mag()</li>
 
</ul>
 
</ul>

Latest revision as of 08:05, 28 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

  • Graphically -> add head to tail
  • Algebraically -> add components [3, 3] + [1, 2] = [4, 5]
  • PVector.add(v1, v2);
  • vec.add(v);

Subtraction

  • Graphically -> flip the direction of one vector, then add
  • Algebraically -> subtract components [3, 3] - [1, 2] = [2, 1]
  • PVector.sub(v1, v2);
  • vec.sub(v);

Scale

  • Graphically -> stretch or shrink
  • Algebraically -> multiply components by scalar [1,3] * 2 = [2, 6]
  • PVector.mult(float);

Calculate Magnitude

  • Graphically -> measure length
  • Algebraically -> use Pythagorean theorem
  • PVector.mag()