ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Alan Braslau via ntg-context <ntg-context@ntg.nl>
To: Thangalin <thangalin@gmail.com>
Cc: Alan Braslau <alan.braslau@icloud.com>,
	mailing list for ConTeXt users <ntg-context@ntg.nl>
Subject: Re: atan2 function
Date: Fri, 14 Oct 2022 16:42:12 -0600	[thread overview]
Message-ID: <20221014164212.3d187bb2@boo.my.domain> (raw)
In-Reply-To: <CAANrE7p6V7XP6s_-Aj2F3e=XBni_jVyXFB2PGeihK4FxESjb=A@mail.gmail.com>

On Fri, 14 Oct 2022 11:59:49 -0700
Thangalin <thangalin@gmail.com> wrote:

> I don't think an atantwo is needed. I *thought* I had read somewhere
> that atan( y, x ) was equivalent to calling atan2 in Lua. Ensuring
> there's no breakage when x == y would be nice, though. It was a little
> surprising to see angle return degrees rather than radians, but it
> does simplify my code:
> 
>       dc := vbc - vac;
>       dr := vbr - var;
>       vi := 0;
> 
>       if not( dc == dr ):
>         vi := round( angle( dc, dr ) / 60 );
>       fi;
> 
>       % Compute the direction towards the first segment (to vertex of
> an edge). vangle := vi * 60 * pi / 180;
> 
> Even simpler would be:
> 
>       dc := vbc - vac;
>       dr := vbr - var;
>       vi := round( angle( dc, dr ) / 60 ); % returns 0 when dc == dr
> 
>       % Compute the direction towards the first segment (to vertex of
> an edge). vangle := vi * 60 * pi / 180;
> 
> Or accepting a third argument as the return value in the special case:
> 
>       vi := round( angle( dc, dr, 0 ) / 60 ); % returns 0 when dc ==
> dr
> 
> Cheers!

vi := if (dc = dr) : 0 else : round (angle(dc,dr)/60) fi ;

Alan
___________________________________________________________________________________
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 22:42 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
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 [this message]
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=20221014164212.3d187bb2@boo.my.domain \
    --to=ntg-context@ntg.nl \
    --cc=alan.braslau@icloud.com \
    --cc=thangalin@gmail.com \
    /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).