FSOSS 2010/processing.js/vectors

From CDOT Wiki
Revision as of 21:09, 27 October 2010 by Asalga (talk | contribs)
Jump to: navigation, search

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)