
in the above image ineed the angle between the two points
if green dot is considered as origin (px,py) ie (0,0) and red dot is (ax,ay)
by the way in the above image angle should be around 45 degree.... acute angle
more ex:
3:00 is 0 degree 12:00 is 90 degree 9:00 is 180 degree 6:00 is 270 degree
here's the code i have tried so far:
function angle(cx, cy, ex, ey) {
var dy = ey - cy;
var dx = ex - cx;
var theta = Math.atan2(dy, dx); // range (-PI, PI]
theta *= 180 / Math.PI; // rads to degs, range (-180, 180]
if (theta < 0) theta = 360 + theta; // range [0, 360)
return theta;
}
Try this out, Working fine for me.
function angle(cx, cy, ex, ey) {
var dy = ey - cy;
var dx = ex - cx;
var theta = Math.atan2(dy, dx); // range (-PI, PI]
theta *= 180 / Math.PI; // rads to degs, range (-180, 180]
//if (theta < 0) theta = 360 + theta; // range [0, 360)
return theta;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With