I have a label where i move the marker around freely through hotspots (xins and yins).
I don't understand how to code the line to stop at the perimeter of the circle. If I knew how ATAN works I could do this but i get an error when trying to use ATAN.
Solved! Go to Solution.
@Mats_Knutsson See if this works after your hotspots...
dLine = SQR(xIns^2 + yIns^2) - rsp IF xIns > 0 THEN aLine = ATN(yIns / xIns) ELSE aLine = ATN(yIns / xIns) + 180 LINE2 0,0, dline * COS(aLine), dLine * SIN(aLine) CIRCLE2 xIns, yIns, rsp TEXT2 xIns, yIns, stName
@Peter Baksa I did think about it & it only fails at exactly (?) 90 / 270 degrees. I know GDL has a problem with real numbers and zero comparison checks e.g. If A = B is replaced with ABS ( A - B ) < eps. What tolerance / formula would be relevant to
ATN ( A / B ) to error trap when B = 0.0?
Yes, there are circumstances when you can be sure the input isn't on the Y axis because some parameters forbid that, and it wouldn't be sensible architecturally. But there could be circumstances where a draggable hotspot would be set to 90° deliberately.
Maybe this is where the ATN / ATAN confusion came from: most programming languages have a non-trigonometric ATAN2 function taking an x and an y coordinate and returning the points' polar coordinate, handling all the cases where ATN could go wrong. GDL doesn't have such, but it can be written as a short subroutine containing a few ifs.
EPS can be avoided by using > from the other way you would use <=.
A working example returning degrees in range (-180...180]:
if abs(_x) > 0 then
_atan2 = atn(_y / _x) + 90 * (1 - sgn(_x)) * (1 - 2 * (sgn(_y) < 0))
_atan2 = sgn(_y * (abs(_y) > 0)) * 90