[NTG-context] atan2 function
Alan Braslau
alan.braslau at icloud.com
Sat Oct 15 00:42:12 CEST 2022
On Fri, 14 Oct 2022 11:59:49 -0700
Thangalin <thangalin at 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
More information about the ntg-context
mailing list