Re: [NTG-context] atan2 function

2022-10-14 Thread Alan Braslau via ntg-context
On Fri, 14 Oct 2022 16:09:41 -0700 Thangalin wrote: > Would making the conditional part of the API be useful to others? Of course, $\tan^{-1}(\pm 1)$ is undefined (mathematically). Alan ___ If your question is of

Re: [NTG-context] atan2 function

2022-10-14 Thread Thangalin via ntg-context
That's certainly tighter, thank you, Alan. Would making the conditional part of the API be useful to others? Cheers! On Fri, Oct 14, 2022 at 3:42 PM Alan Braslau wrote: > > On Fri, 14 Oct 2022 11:59:49 -0700 > Thangalin wrote: > > > I don't think an atantwo is needed. I *thought* I had read

Re: [NTG-context] atan2 function

2022-10-14 Thread Alan Braslau via ntg-context
On Fri, 14 Oct 2022 11:59:49 -0700 Thangalin 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

Re: [NTG-context] atan2 function

2022-10-14 Thread Thangalin via ntg-context
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:

Re: [NTG-context] atan2 function

2022-10-14 Thread Alan Braslau via ntg-context
On Fri, 14 Oct 2022 10:07:19 +0200 Hans Hagen via ntg-context wrote: > So you suggest to add atantwo? As side note, you can redure your > definition to: > > vardef atantwo(expr dy, dx) = > if dx == 0 : > if dy < 0 : - fi pi / 2 > else : >

Re: [NTG-context] atan2 function

2022-10-14 Thread luigi scarso via ntg-context
On Fri, 14 Oct 2022 at 14:58, Taco Hoekwater via ntg-context < ntg-context@ntg.nl> wrote: > > > > On 14 Oct 2022, at 14:26, Alan Braslau via ntg-context < > ntg-context@ntg.nl> wrote: > > > > Are you using MP in scaled integer or in doubleprecision mode? > > > > I have not looked into the MP

Re: [NTG-context] atan2 function

2022-10-14 Thread Taco Hoekwater via ntg-context
> On 14 Oct 2022, at 14:26, Alan Braslau via ntg-context > wrote: > > Are you using MP in scaled integer or in doubleprecision mode? > > I have not looked into the MP angle operator code, but my suspicion is that > it is based on some super-clever John Hobby scheme optimized for scaled >

Re: [NTG-context] atan2 function

2022-10-14 Thread Alan Braslau via ntg-context
Are you using MP in scaled integer or in doubleprecision mode? I have not looked into the MP angle operator code, but my suspicion is that it is based on some super-clever John Hobby scheme optimized for scaled integer calculations. Hans has integrated the entire math library (and more) into

Re: [NTG-context] atan2 function

2022-10-14 Thread Hans Hagen via ntg-context
On 10/14/2022 2:35 AM, Max Chernoff via ntg-context wrote: 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:

Re: [NTG-context] atan2 function

2022-10-13 Thread Max Chernoff via ntg-context
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 ) =

Re: [NTG-context] atan2 function

2022-10-13 Thread Thangalin via ntg-context
Thank you, Max. The angle function doesn't appear to provide the same calculation as my atantwo in all cases. https://pdfhost.io/v/Oqj7XmibJ_scaled The shorter line segment should be directed towards the vertex closest to the longer line segment. I tried using both: theta := angle( dx, dy

Re: [NTG-context] atan2 function

2022-10-13 Thread Max Chernoff via ntg-context
Hi, > How is atan2 called? I rolled my own as follows: > Is atan with two parameters supposed to behave like atan2? At mp-math.mpxl:167 there is: vardef atan primary x = angle(1,x) enddef ; The MetaPost manual says: The angle operator takes a pair and computes the