Inconsitent PVector.angleBetween() results.


I am trying to calculate the angle between two PVectors. For some reaosn the results seem inconsitent. First i will show you some test code:

PVector point1, point2, point3, point4;
int r;
float angle1to2, angle1to3, angle1to4;

void setup () {
  size(700, 400);
  point1 = new PVector(100, 100);
  point2 = new PVector(300, 100);
  point3 = new PVector(100, 300);
  point4 = new PVector(400, 100);
  r = 5;

void draw () {
  angle1to2 = PVector.angleBetween(point1, point2);
  angle1to3 = PVector.angleBetween(point1, point3);
  angle1to4 = PVector.angleBetween(point1, point4);

  ellipse(point1.x, point1.y, r*2, r*2);
  text("1", point1.x, point1.y);

  ellipse(point2.x, point2.y, r*2, r*2);
  text("2 - angle from 1: " + degrees(angle1to2), point2.x, point2.y-20);

  ellipse(point3.x, point3.y, r*2, r*2);
  text("3 - angle from 1: " + degrees(angle1to3), point3.x, point3.y);

  ellipse(point4.x, point4.y, r*2, r*2);
  text("4 - angle from 1: " + degrees(angle1to4), point4.x, point4.y);


As you can see I have four points and am trying to calculate the angles between them. The angles between points show as:

Point1 - Point2 : 26.56505°
Point1 - Point3 : 26.56505°
Point1 - Point4 : 30.963757°

These angles seem to be largely inconsistent to me. For instance although points 2 and 3 are at a right angle to each other from point 1 they present the same angle. For points 2 and 4, although they are the same angle from 1 they present completely different angles.

To help visualise this here is a picture of the output of the above program:


What am I missing here?

Thank you for your time and help!


  • If you draw a line from the top left hand corner of the screen [0,0] to each of the four points then look at the angles between the lines and compare them with the results you got you will see that they are consistent.

Sign In or Register to comment.