ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Max Chernoff via ntg-context <ntg-context@ntg.nl>
To: ntg-context@ntg.nl
Cc: Max Chernoff <mseven@telus.net>
Subject: Re: atan2 function
Date: Thu, 13 Oct 2022 18:35:51 -0600	[thread overview]
Message-ID: <b36283d0b4e89cf0cb2b41687eb684fb2d323dfd.camel@telus.net> (raw)
In-Reply-To: <CAANrE7oZ1_Y=at85zuh1eZLDSJF=QsLMHwqBhXS=oBAs8_X-VA@mail.gmail.com>


Hi,

> The angle function doesn't appear to provide the same calculation as
> my atantwo in all cases.

They both give the same results, but "angle" gives a result in degrees
while "atantwo" gives a result in radians. This demo:

   \startMPpage
       vardef atantwo( expr dy, dx ) =
           save theta;
   
           numeric theta;
   
           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
       enddef;
   
       def showangles(expr dx, dy) =
           message "---------------"
           message "atantwo " & decimal atantwo(dy, dx)
           message "angle " & decimal (angle(dx, dy) * pi / 180)
           message "angle " & decimal angle(dx, dy)
           message "(" & decimal dx & ", " & decimal dy & ")"
       enddef;
   
       showangles(1, 0);
       showangles(1, 1);
       showangles(0, 1);
       showangles(-1, 1);
       showangles(-1, 0);
       showangles(-1, -1);
       showangles(0, -1);
       showangles(1, -1);
   \stopMPpage

gives:

   (1, 0)
   angle 0
   angle 0
   atantwo 0
   ---------------
   (1, 1)
   angle 45
   angle 0.78539816339744828
   atantwo 0.78539816339744828
   ---------------
   (0, 1)
   angle 90
   angle 1.5707963267948966
   atantwo 1.5707963267948966
   ---------------
   (-1, 1)
   angle 135
   angle 2.3561944901923448
   atantwo 2.3561944901923448
   ---------------
   (-1, 0)
   angle 180
   angle 3.1415926535897931
   atantwo 3.1415926535897931
   ---------------
   (-1, -1)
   angle -135
   angle -2.3561944901923448
   atantwo -2.3561944901923448
   ---------------
   (0, -1)
   angle -90
   angle -1.5707963267948966
   atantwo -1.5707963267948966
   ---------------
   (1, -1)
   angle -45
   angle -0.78539816339744828
   atantwo -0.78539816339744828
   ---------------
   
Thanks,
-- Max
___________________________________________________________________________________
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
___________________________________________________________________________________

  reply	other threads:[~2022-10-14  0:35 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-13  5:40 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 [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=b36283d0b4e89cf0cb2b41687eb684fb2d323dfd.camel@telus.net \
    --to=ntg-context@ntg.nl \
    --cc=mseven@telus.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).