PVector.angleBetween
in
Programming Questions
•
1 year ago
Hello all,
I don't understand PVector.angleBetween or it doesn't give the results I expect.
I thought it would work like in a circle: you hand it the middle of the circle as PVector and another point on the circumference as PVector and you got the angle (the same thing that with cos and sin would give the difference of x and y).
But I don't think it does....
So what does it really do... and what can I do to achieve what I want?
I post my Code to clarify. I know it gives you rad and I convert it to degrees but still...
Greetings, Chrisir
I don't understand PVector.angleBetween or it doesn't give the results I expect.
I thought it would work like in a circle: you hand it the middle of the circle as PVector and another point on the circumference as PVector and you got the angle (the same thing that with cos and sin would give the difference of x and y).
But I don't think it does....
So what does it really do... and what can I do to achieve what I want?
I post my Code to clarify. I know it gives you rad and I convert it to degrees but still...
Greetings, Chrisir
- PVector middle;
- PVector Pos1=new PVector(100, 50);
- PVector Pos2=new PVector(550, 150);
- PVector Pos3=new PVector(550, 250);
- PVector Pos4=new PVector(550, 350);
- PVector Pos5=new PVector(550, 550);
- void setup () {
- size(700, 700);
- middle=new PVector(350, 350);
- }
- void draw () {
- background (0);
- showPVector(middle, color(255, 0, 0));
- showPVector(Pos1, color(255, 250, 0));
- showPVector(Pos2, color(255, 0, 250));
- showPVector(Pos3, color(255, 0, 250));
- showPVector(Pos4, color(55, 55, 0));
- showPVector(Pos5, color(55, 55, 233));
- }
- void showPVector(PVector myPVector, color col) {
- fill(col);
- ellipse(myPVector.x, myPVector.y, 10, 10);
- String myText = nf(PVector.angleBetween( middle, myPVector ), 0, 2)
- + " rad or "
- + nf(degrees(PVector.angleBetween( middle, myPVector )), 0, 2)
- + "°";
- text(myText, myPVector.x+13, myPVector.y);
- }
1