ID:1545010
 
(See the best response by Kaiochao.)
Code:
proc
get_angle_nums(ax=45,ay=45,bx=45,by=45)
var/val = sqrt((bx - ax) * (bx - ax) + (by - ay) * (by - ay))
if(!val) return 0
var/ar = arccos((bx - ax) / val)
var/deg = round(360 - (by - ay >= 0 ? ar : -ar), 1)
while(deg > 360) deg -= 360
while(deg < 0) deg += 360
return deg


Problem description:
I'm using this to return a degree, it works however I'm having an issue with figuring out how to return the degree of a turf, for movable atoms it works okay.

Any suggestions? Or perhaps simplifications/ improvements ?
Best response
This is what I use to get an angle:
// atan2(-1, 1) == 315 (northwest)
// angles are kept between 0 and 360.
proc/atan2(x, y) return (x || y) && (x >= 0 ? arccos(y / sqrt(x * x + y * y)) : 360 - arccos(y / sqrt(x * x + y * y)))

// or
proc/atan2(x, y)
if(x || y)
. = arccos(y / sqrt(x * x + y * y))
if(x < 0)
return 360 - .
else return 0


If you're using my "absolute position" library, you should be able to use atom.Cx() and atom.Cy() as the (ax, ay) and (bx, by) points. They correspond to the center of the atom's bounding box.

e.g.
proc/get_angle(atom/A, atom/B)
return atan2(
B.Cx() - A.Cx(),
B.Cy() - A.Cy())