How can i get the degree direction from x1 y1 to x2 y2?example…
x1 = 0 y1 = 0
x2 = 100 y2 = 100
Its equals 45°…
I tried to make it myself but it not 100% accurate method…its showing 10-15 more degrees than needed…
Example:
float x1, y1, x2, y2;
void setup(){
size(800,800);
x1 = 400;
y1 = 400;
}
void draw(){
x2 = mouseX;
y2 = mouseY;
background(0);
stroke(255);
line(x1,y1,x2,y2);
line(x1, y1, x1+100, y1);
noFill();
float a = atan2(y2-y1,x2-x1);
arc(x1,y1,80,80, min(0,a), max(0,a) );
text( degrees(a), mouseX, mouseY-20 );
}
void mousePressed(){
x1 = mouseX;
y1 = mouseY;
}
1 Like