2022-01-12 05:11 AM
Hi,
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.
Br,
Mats
Solved! Go to Solution.
2022-01-12 08:07 AM
@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
2022-01-12 05:46 AM
Gegenkathete / Ankathete = TAN(alfa)
alfa = ATN(Gegenkathete / Ankathete)
2022-01-12 05:52 AM
Hi!
If I understood correctly, you would like to get the arc tangent of x, but you get an error message, correct? The function uses the argument "ATN" instead of "ATAN", see if you get the desired outcome with that.
2022-01-12 07:06 AM
Ah...I read a doc where it was ATAN. Will try ATN instead. Thx
2022-01-12 08:07 AM
@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
2022-01-12 12:16 PM - edited 2022-01-12 12:17 PM
Gr8 thanks 🙂
2022-01-25 06:30 AM
Also be extra careful not to divide by 0.
2022-01-25 07:24 AM
Living on the edge...
2022-01-25 03:15 PM
@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?
2022-01-26 12:11 AM
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))
else
_atan2 = sgn(_y * (abs(_y) > 0)) * 90
endif
2022-01-26 11:03 PM
Great snippet!!! Could you at HQ arrange a site with clever code snippets like this?
2022-01-26 06:59 AM
Thank you. I will tuck that one away for future use. 👍