A PVector(100, 100) is not a point at (100,100) it's a vector from the origin (0,0) to point(100, 100). So your middle PVector is a vector from the origin to (350, 350). The angle of this vector is 45 degrees. Your Pos5 PVector is a vector from the origin to (550, 550);. The angle of this vector is also 45 degrees. So the angleBetween the middle and the Pos5 Pvector is 0. For all the other it's the same, the method gives the angle between one vector and another.
To understand better what angleBetween does add the following lines to your sketch:
- // add to draw()
- showPVector(new PVector(mouseX, mouseY), color(55, 55, 233));
- // add to showPVector()
- stroke(col);
- line(0,0, myPVector.x, myPVector.y);
You will notice as described above, that a PVector on the 45 degree (middle) line will give 0 degrees, while (0, mouseX) or (mouseY, 0) will give 45 degrees. So it's just the angle from one vector compared to another. Also see below.
Code Example- PVector x = new PVector(1, 0);
- PVector y = new PVector(0, 1);
- float angle = PVector.angleBetween(x, y);
- println(degrees(angle)); // 90 degrees
- exit();