Difference between revisions of "FSOSS 2010/processing.js/vectors"
Line 11: | Line 11: | ||
<b>Addition</b> | <b>Addition</b> | ||
<ul> | <ul> | ||
− | <li> | + | <li>Graphically -> add head to tail</li> |
− | <li> | + | <li>Algebraically -> add components [3, 3] + [1, 2] = [4, 5]</li> |
<li>PVector.add(PVector)</li> | <li>PVector.add(PVector)</li> | ||
</ul> | </ul> | ||
Line 18: | Line 18: | ||
<b>Scale</b> | <b>Scale</b> | ||
<ul> | <ul> | ||
− | <li> | + | <li>Graphically -> stretch or shrink</li> |
− | <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> |
Revision as of 21:14, 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
- Graphically -> add head to tail
- Algebraically -> add components [3, 3] + [1, 2] = [4, 5]
- PVector.add(PVector)
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()