POV-Ray : Newsgroups : povray.general : I have a problem with atan2() : Re: I have a problem with atan2() Server Time
19 Apr 2024 12:07:34 EDT (-0400)
  Re: I have a problem with atan2()  
From: Bald Eagle
Date: 18 Oct 2021 15:25:00
Message: <web.616dc8e6f55768361f9dae3025979125@news.povray.org>
Alain Martel <kua### [at] videotronca> wrote:


> > And therefore, my problem is when A AND B are equal to zero.
> >
> > Lot of datas to deal with, the debugging will be long...
> > (i'm working on the visualization of complex functions with domain
> > coloring)
> >
> >
> >
> Add a test to see if both A and B are zero, and replace that with some
> small value for B. It could be something like the following just before
> the call to atan2 :
>
> #if (A=0 ! B=0) #declare B= 0.001; #end
> ... atan2(A,B) ...

This problem seems to come up a fair number of times

http://news.povray.org/web.5d4222c54ed4290e4eec112d0%40news.povray.org

And I've had the same sorts of problems and even segmentation faults and core
dumps triggered by similar issues with acos and asin.

Off the top of my head, the way I see it, is that if you're taking atan2 (A/B),
and both A and B are zero, then let's assume arguendo that A is held constant at
zero throughout the evaluation of all B's.  0/N is always zero, so the above
suggested solution and past similar solutions seem to be a good way to address
the issue.

I typically use the usual 1x10^-6 value used for coincident surface stuff and
whatnot in POV-Ray, but maybe Bill P or someone else could suggest a better
value, or that atan2 values could be graphed for a range of B values to get a
better idea of where the point of diminishing returns / insignificant
differences in results lies.

Perhaps it might be a good idea to have a few wrapper macros to perform these
calculations with effective and reliable protective measures proceding the
evaluation of atan2, asin, and acos.


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.