POV-Ray : Newsgroups : povray.advanced-users : Does wrapping atan2(0,0) avoid the domain error? : Re: Does wrapping atan2(0,0) avoid the domain error? Server Time
28 Mar 2024 09:02:10 EDT (-0400)
  Re: Does wrapping atan2(0,0) avoid the domain error?  
From: Tor Olav Kristensen
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

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