POV-Ray : Newsgroups : povray.advanced-users : Does wrapping atan2(0,0) avoid the domain error? Server Time
4 Feb 2023 23:01:57 EST (-0500)
  Does wrapping atan2(0,0) avoid the domain error? (Message 1 to 5 of 5)  
From: Cousin Ricky
Subject: Does wrapping atan2(0,0) avoid the domain error?
Date: 5 Dec 2022 14:49:00
Message: <638e4b2c$1@news.povray.org>
I have a situation where it is possible to pass zero as both arguments
to atan2(), which is the one case where the function fails.  But while
attempting to find a workaround for this situation, I discovered that
simply calling atan2(0,0) from within a user-defined function avoids the
domain error!

I don't know whether this is intended POV-Ray behavior or just a fluke
of my computer OS.

Can you all try the following scene file with -F and report what the
message window says, along with your operating system and POV version?
My system writes 0.000000 for the first line, and fails on the second.
I'd like to know if this is consistent behavior across all operating
systems.  Or perhaps Chris or Thorsten can tell us if this is intended
behavior?

----------[BEGIN CODE]----------
#version max (3.5, min (3.8, version));
global_settings { assumed_gamma 1 }
#declare fn_Atan2 = function (y, x) { atan2 (y, x) }
#debug concat ("atan2 (0,0) with wrapper = ", str (fn_Atan2 (0,0), 0,
6), "\n")
#debug concat ("bare atan2 (0,0) = ", str (atan2 (0,0), 0, 6), "\n")
-----------[END CODE]-----------


Post a reply to this message

From: jr
Subject: Re: Does wrapping atan2(0,0) avoid the domain error?
Date: 5 Dec 2022 15:15:00
Message: <web.638e5098dfb43945c0ce110b6cde94f1@news.povray.org>
hi,

Cousin Ricky <ric### [at] yahoocom> wrote:
> ...
> Can you all try the following ...

POV-Ray 3.7.0.8.unofficial

atan2 (0,0) with wrapper = 0.000000
File 'cr.pov' line 6: Parse Error: Domain error in atan2!


regards, jr.


Post a reply to this message

From: Tor Olav Kristensen
Subject: Re: Does wrapping atan2(0,0) avoid the domain error?
Date: 5 Dec 2022 19:30:00
Message: <web.638e8c31dfb439454829143889db30a9@news.povray.org>
Cousin Ricky <ric### [at] yahoocom> wrote:
> I have a situation where it is possible to pass zero as both arguments
> to atan2(), which is the one case where the function fails.  But while
> attempting to find a workaround for this situation, I discovered that
> simply calling atan2(0,0) from within a user-defined function avoids the
> domain error!
>
> I don't know whether this is intended POV-Ray behavior or just a fluke
> of my computer OS.
>...

Hi Ricky

I recommend that you don't make you code rely on a missing domain error.
(That it is missing could be considered a bug.)

Instead, I suggest that you write a function that deals with the
problematic values explicitly. E.g. like this:

#declare Atan2_Fn =
    function(y, x) {
        select(
            y,
            atan2(y, x),
            select(
                x,
                atan2(y, x),
                0,  // Insert the result you want for Atan2_Fn(0, 0)
                atan2(y, x)
            ),
            atan2(y, x)
        )
    }
;

- or like this if you want 0 returned for AltAtan2_Fn(0, 0):

#declare AltAtan2_Fn =
    function(y, x) {
        atan2(
            y,
            select(
                x,
                x,
                select(
                    y,
                    x,
                    1,
                    x
                ),
                x
            )
        )
    }
;

--
Tor Olav
http://subcube.com
https://github.com/t-o-k


Post a reply to this message

From: kurtz le pirate
Subject: Re: Does wrapping atan2(0,0) avoid the domain error?
Date: 9 Dec 2022 12:36:11
Message: <6393720b$1@news.povray.org>
On 05/12/2022 20:48, Cousin Ricky wrote:
> I have a situation where it is possible to pass zero as both arguments
> to atan2(), which is the one case where the function fails.  But while
> attempting to find a workaround for this situation, I discovered that
> simply calling atan2(0,0) from within a user-defined function avoids the
> domain error!
> 
> I don't know whether this is intended POV-Ray behavior or just a fluke
> of my computer OS.
> 
> Can you all try the following scene file with -F and report what the
> message window says, along with your operating system and POV version?
> My system writes 0.000000 for the first line, and fails on the second.
> I'd like to know if this is consistent behavior across all operating
> systems.  Or perhaps Chris or Thorsten can tell us if this is intended
> behavior?
> 
> ----------[BEGIN CODE]----------
> #version max (3.5, min (3.8, version));
> global_settings { assumed_gamma 1 }
> #declare fn_Atan2 = function (y, x) { atan2 (y, x) }
> #debug concat ("atan2 (0,0) with wrapper = ", str (fn_Atan2 (0,0), 0,
> 6), "\n")
> #debug concat ("bare atan2 (0,0) = ", str (atan2 (0,0), 0, 6), "\n")
> -----------[END CODE]-----------
> 


Further details here :
<http://news.povray.org/povray.general/thread/%3C616bfd9d%241%40news.povray.org%3E/?ttop=438714&toff=50>




-- 
Kurtz le pirate
Compagnie de la Banquise


Post a reply to this message

From: Cousin Ricky
Subject: Re: Does wrapping atan2(0,0) avoid the domain error?
Date: 14 Dec 2022 12:21:13
Message: <639a0609$1@news.povray.org>
On 2022-12-09 13:36 (-4), kurtz le pirate wrote:
> 
> Further details here :
>
<http://news.povray.org/povray.general/thread/%3C616bfd9d%241%40news.povray.org%3E/?ttop=438714&toff=50>

Yes, and it was the part about atan2(0,0) being different on different
systems that I'm leery about.  But it makes sense that there would be no
consistency; any angle at all would satisfy (0,0).


Post a reply to this message

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