ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* atan2 function
@ 2022-10-13  5:40 Thangalin via ntg-context
  2022-10-13  6:42 ` Max Chernoff via ntg-context
  0 siblings, 1 reply; 13+ messages in thread
From: Thangalin via ntg-context @ 2022-10-13  5:40 UTC (permalink / raw)
  To: mailing list for ConTeXt users; +Cc: Thangalin

Hi there,

How is atan2 called? I rolled my own as follows:

% SOT
\startuseMPgraphic{HexGridBaseGraphic}
  vardef atantwo( expr ax, ay, bx, by ) =
    save theta;

    numeric dx;
    numeric dy;
    numeric theta;

    dx := bx - ax;
    dy := by - ay;
    theta := 0;

    if (dx > 0):
      theta := atan( dy / dx );
    elseif (dx < 0) and (dy >= 0):
      theta := atan( dy / dx ) + pi;
    elseif (dx < 0) and (dy < 0):
      theta := atan( dy / dx ) - pi;
    elseif (dx == 0) and (dy > 0):
      theta := pi / 2;
    elseif (dx == 0) and (dy < 0):
      theta := -pi / 2;
    fi;

    %theta := atan( dy, dx );

    theta
  enddef;
% EOT

When this runs, the expected result is generated:

https://pdfhost.io/v/xdNxANU18_scaled

When uncommenting "atan( dy, dx )", an unexpected result is generated:

https://pdfhost.io/v/QdfU89IL._scaled

Is atan with two parameters supposed to behave like atan2?

Cheers!
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / https://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : https://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : https://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2022-10-15  1:22 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-13  5:40 atan2 function Thangalin via ntg-context
2022-10-13  6:42 ` Max Chernoff via ntg-context
2022-10-13 19:51   ` Thangalin via ntg-context
2022-10-14  0:35     ` Max Chernoff via ntg-context
2022-10-14  8:07       ` Hans Hagen via ntg-context
2022-10-14 14:40         ` Alan Braslau via ntg-context
2022-10-14 18:59           ` Thangalin via ntg-context
2022-10-14 22:42             ` Alan Braslau via ntg-context
2022-10-14 23:09               ` Thangalin via ntg-context
2022-10-15  1:22                 ` Alan Braslau via ntg-context
2022-10-14 12:26     ` Alan Braslau via ntg-context
2022-10-14 12:58       ` Taco Hoekwater via ntg-context
2022-10-14 13:05         ` luigi scarso via ntg-context

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).