cancel
Showing results for 
Search instead for 
Did you mean: 
EN
cancel
Showing results for 
Search instead for 
Did you mean: 
Mats_Knutsson
Mentor

GDL Trigonometry question

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

 

 

gdl atan.jpg

AC 25 SWE Full

HP Zbook Fury 15,6 G8. 32 GB RAM. Nvidia RTX A3000.
1 Solution

Accepted Solutions
DGSketcher
Legend

@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
Apple iMac Intel i9 / macOS Sonoma / AC27UKI (most recent builds.. if they work)

Go to post

11 Replies 11
Jochen Suehlo
Moderator Emeritus

Gegenkathete / Ankathete = TAN(alfa)

alfa = ATN(Gegenkathete / Ankathete)

Jochen Suehlo . AC12-29 . MAC OSX 14.4 . WIN11
GDL object creation: b-prisma.de
Zsuzsanna Bori
Graphisoft
Graphisoft

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.

 

Mats_Knutsson
Mentor

Ah...I read a doc where it was ATAN. Will try ATN instead. Thx

AC 25 SWE Full

HP Zbook Fury 15,6 G8. 32 GB RAM. Nvidia RTX A3000.
DGSketcher
Legend

@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
Apple iMac Intel i9 / macOS Sonoma / AC27UKI (most recent builds.. if they work)
Mats_Knutsson
Mentor

Gr8 thanks 🙂

 

https://youtu.be/NPs0vPolWhs

AC 25 SWE Full

HP Zbook Fury 15,6 G8. 32 GB RAM. Nvidia RTX A3000.
Peter Baksa
Graphisoft
Graphisoft

Also be extra careful not to divide by 0.

Péter Baksa
Software Engineer, Library
Graphisoft SE, Budapest
Mats_Knutsson
Mentor

Living on the edge...

AC 25 SWE Full

HP Zbook Fury 15,6 G8. 32 GB RAM. Nvidia RTX A3000.
DGSketcher
Legend

@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?

Apple iMac Intel i9 / macOS Sonoma / AC27UKI (most recent builds.. if they work)
Peter Baksa
Graphisoft
Graphisoft

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
Péter Baksa
Software Engineer, Library
Graphisoft SE, Budapest

Didn't find the answer?

Check other topics in this Forum

Back to Forum

Read the latest accepted solutions!

Accepted Solutions

Start a new conversation!