ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Taco Hoekwater via ntg-context <ntg-context@ntg.nl>
To: mailing list for ConTeXt users <ntg-context@ntg.nl>
Cc: Taco Hoekwater <taco@bittext.nl>
Subject: Re: atan2 function
Date: Fri, 14 Oct 2022 14:58:31 +0200	[thread overview]
Message-ID: <A62ACF57-AC88-4B8C-ABDE-FBA0E8DD9C5D@bittext.nl> (raw)
In-Reply-To: <ee6ed44a-8b4d-b62c-cc49-64f6adde229b@icloud.com>



> 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 angle operator code, but my suspicion is that it is based on some super-clever John Hobby scheme optimized for scaled integer calculations.

The scaled version of “angle” is a handwritten approximation in web, not using
any math library. I really doubt that that code is faster than calling atan2()
on a modern machine, but I’ve kept it in because using a lib might give slightly 
different results.

The double version of “angle" uses atan2() internally already, so that the 
atantwo macro is just duplicating the internals for that case.

The decimal version of “angle’ uses a dedicated decNumberAtan2() library call.

> 
> 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.
>> 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 );
>>     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:
>> https://en.wikipedia.org/wiki/Atan2#Definition_and_computation
>> 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:
>> https://pdfhost.io/v/1T4jgBnxh_scaled
>> On Wed, Oct 12, 2022 at 11:42 PM Max Chernoff <mseven@telus.net> wrote:
>>> 
>>> 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 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".
>>> 
>>> 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
>> ___________________________________________________________________________________
> 
> \
> 
> ___________________________________________________________________________________
> 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
> ___________________________________________________________________________________

— 
Taco Hoekwater              E: taco@bittext.nl
genderfluid (all pronouns)



___________________________________________________________________________________
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 12:58 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
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 [this message]
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=A62ACF57-AC88-4B8C-ABDE-FBA0E8DD9C5D@bittext.nl \
    --to=ntg-context@ntg.nl \
    --cc=taco@bittext.nl \
    /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).