Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

If you add to vectors together, the resulting vector is the equivalent of stacking the vectors end to end. The maths behind it is simple, just add the x positions of each vector together and then add the y positions together. Adding vectors together can be used to simulate simple physics like the effect of wind or gravity, so for every step forward a game character might have a wind vector added to their movement vector. If a character in a game jumps while moving forward, then we also want to add the vectors of the upward movement with the forward motion, and then in reverse when they fall back down. 

...

Normalising

A normalised vector or a unit vector has had its magnitude set to one, with the direction left unchanged. A unit vector shows us a direction and can be easily scaled by any value. 

Finding the magnitude

You can find the magnitude (the length) using Pythagorean theorem:(Diagram 7.  sqrt(x^2 + y^2. A magnitude and unit vector can easily be recombined to create  

c = (4, 5) 

sqrt(4^2 + 5^2))

PVector

Processing has a vector class called ‘PVector‘, which can be two or three dimensions. Basic vector maths are included in a number of methods of the PVector class, so processing can do all the hard work for you.

...