#### Howdy, Stranger!

We are about to switch to a new forum software. Until then we have removed the registration on this forum.

# Inconsitent PVector.angleBetween() results.

Hi,

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;
textSize(20);
}

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

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

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

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

fill(255);
ellipse(point4.x, point4.y, r*2, r*2);
fill(0);
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!

Tagged: