[NTG-context] atan2 function
alan.braslau at icloud.com
Fri Oct 14 14:26:42 CEST 2022
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 lmtx.
On 13/10/22 13/10/22, 13:51, Thangalin via ntg-context wrote:
> Thank you, Max.
> The angle function doesn't appear to provide the same calculation as
> my atantwo in all cases.
> The shorter line segment should be directed towards the vertex closest
> to the longer line segment. I tried using both:
> theta := angle( dx, dy );
> theta := angle( dy, dx );
> Neither made a difference, in some cases the angle differs from what I'd expect.
> My implementation is based on the first version given here:
> I have something that works, so this is more of a curiosity as to
> there being a difference between my implementation of atantwo and the
> angle function.
> Here's an example with many lines and the angle function:
> On Wed, Oct 12, 2022 at 11:42 PM Max Chernoff <mseven at telus.net> wrote:
>>> 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 two-argument
>> arctangent; i.e., angle is the inverse of the dir operator
>> So it looks like "angle" is the function that you want for "atan2".
>> -- Max
> If your question is of interest to others as well, please add an entry to the Wiki!
> maillist : ntg-context at 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
More information about the ntg-context