POV-Ray : Newsgroups : povray.advanced-users : What... the hell...? Server Time
31 Oct 2024 14:11:43 EDT (-0400)
  What... the hell...? (Message 1 to 9 of 9)  
From: Orchid XP v2
Subject: What... the hell...?
Date: 11 Mar 2006 16:03:07
Message: <44133b0b$1@news.povray.org>
3.2.1.3.4  Functions

"atan2(A,B): Arc-tangent of (A/B). Returns the angle, measured in 
radians, whose tangent is (A/B). Returns appropriate value even if B is 
zero. Use atan2(A,1) to compute usual atan(A) function."


Um... yeah, OK... so why does atan2(0, 0) give we a fatal parse error?

(POV-Ray v3.6, Windows.)


Post a reply to this message

From: Ken and Timi Cecka
Subject: Re: What... the hell...?
Date: 11 Mar 2006 17:04:00
Message: <44134950@news.povray.org>
Orchid XP v2 wrote:

> 3.2.1.3.4  Functions
> 
> "atan2(A,B): Arc-tangent of (A/B). Returns the angle, measured in
> radians, whose tangent is (A/B). Returns appropriate value even if B is
> zero. Use atan2(A,1) to compute usual atan(A) function."
> 
> 
> Um... yeah, OK... so why does atan2(0, 0) give we a fatal parse error?
> 
> (POV-Ray v3.6, Windows.)

The arguments to atan2 are the rise (A) and run (B) of a tangent line for
which you want to know the angle.  If the line runs (B != 0) but does not
rise (A = 0), you have a horizontal line.  If the line rises (A != 0) but
does not run (B = 0), you have a vertical line.  But if the line does not
rise (A = 0) or run (B = 0), what do you have?  The line does not go
anywhere, so the angle is undefined.

I haven't looked at the pov code, but I expect this is the reason for the
parse error - there's no correct way to evaluate the expression.

Ken


Post a reply to this message

From: Orchid XP v2
Subject: Re: What... the hell...?
Date: 11 Mar 2006 17:06:53
Message: <441349fd$1@news.povray.org>
>>Um... yeah, OK... so why does atan2(0, 0) give we a fatal parse error?
> 
> The arguments to atan2 are the rise (A) and run (B) of a tangent line for
> which you want to know the angle.  If the line runs (B != 0) but does not
> rise (A = 0), you have a horizontal line.  If the line rises (A != 0) but
> does not run (B = 0), you have a vertical line.  But if the line does not
> rise (A = 0) or run (B = 0), what do you have?  The line does not go
> anywhere, so the angle is undefined.

The angle is definitely undefined - but I would be quite happy for POV 
to return *any* angle to me... Now I have to figure out how to get round 
this parse error. :-/

(The number that results is being fed into a rotate statement, so in the 
case of both numbers being zero, whatever rotation ends up happening 
won't make any difference to the final image...)


Post a reply to this message

From: Slime
Subject: Re: What... the hell...?
Date: 11 Mar 2006 18:47:24
Message: <4413618c$1@news.povray.org>
> The angle is definitely undefined - but I would be quite happy for POV
> to return *any* angle to me... Now I have to figure out how to get round
> this parse error. :-/



#declare A = ...;
#declare B = ...;
#if (A != 0 | B != 0)
#declare angle = atan2(A,B);
#else
#declare angle = 0;
#end

 - Slime
 [ http://www.slimeland.com/ ]


Post a reply to this message

From: Warp
Subject: Re: What... the hell...?
Date: 19 Mar 2006 22:44:39
Message: <441e2527@news.povray.org>
Orchid XP v2 <voi### [at] devnull> wrote:
> "atan2(A,B): Arc-tangent of (A/B). Returns the angle, measured in 
> radians, whose tangent is (A/B). Returns appropriate value even if B is 
> zero. Use atan2(A,1) to compute usual atan(A) function."

> Um... yeah, OK... so why does atan2(0, 0) give we a fatal parse error?

  Because the result is not defined. You are basically asking the
direction of a zero vector, which has none.

-- 
                                                          - Warp


Post a reply to this message

From: Orchid XP v2
Subject: Re: What... the hell...?
Date: 20 Mar 2006 07:31:55
Message: <441ea0bb@news.povray.org>
>>"atan2(A,B): Arc-tangent of (A/B). Returns the angle, measured in 
>>radians, whose tangent is (A/B). Returns appropriate value even if B is 
>>zero. Use atan2(A,1) to compute usual atan(A) function."
> 
> 
>>Um... yeah, OK... so why does atan2(0, 0) give we a fatal parse error?
> 
> 
>   Because the result is not defined. You are basically asking the
> direction of a zero vector, which has none.

I just thought the whole point of using atan2 was to _avoid_ divide by 
zero errors.

Sure, if the vector has a length of zero it has no defined direction. 
OTOH, I would imagine in most cases it just wouldn't *matter* what 
number the function returns in this case - just so long as it returns 
something, rather than an error...

Oh well.


Post a reply to this message

From: Chris B
Subject: Re: What... the hell...?
Date: 20 Mar 2006 08:06:10
Message: <441ea8c2$1@news.povray.org>
"Orchid XP v2" <voi### [at] devnull> wrote in message 
news:441ea0bb@news.povray.org...
>>>"atan2(A,B): Arc-tangent of (A/B). Returns the angle, measured in 
>>>radians, whose tangent is (A/B). Returns appropriate value even if B is 
>>>zero. Use atan2(A,1) to compute usual atan(A) function."
>>
>>
>>>Um... yeah, OK... so why does atan2(0, 0) give we a fatal parse error?
>>
>>
>>   Because the result is not defined. You are basically asking the
>> direction of a zero vector, which has none.
>
> I just thought the whole point of using atan2 was to _avoid_ divide by 
> zero errors.
>
> Sure, if the vector has a length of zero it has no defined direction. 
> OTOH, I would imagine in most cases it just wouldn't *matter* what number 
> the function returns in this case - just so long as it returns something, 
> rather than an error...
>
> Oh well.

Hi,

The easy workaround would be to put Slime's solution into your own macro 
e.g. Orchidatan2(A,B) returning the angle.
Then, if you've got a lot of atan2 calls you can just do a global replace.

Regard,
Chris B.


Post a reply to this message

From: Mike Sobers
Subject: Re: What... the hell...?
Date: 26 May 2006 18:40:00
Message: <web.447782ae7e4925a01009749b0@news.povray.org>
Orchid XP v2 <voi### [at] devnull> wrote:
> >>"atan2(A,B): Arc-tangent of (A/B). Returns the angle, measured in
> >>radians, whose tangent is (A/B). Returns appropriate value even if B is
> >>zero. Use atan2(A,1) to compute usual atan(A) function."
> >

> I just thought the whole point of using atan2 was to _avoid_ divide by
> zero errors.
>
> Oh well.


Yes, but not when A and B are BOTH zero.  Then the function is undefined.
You could simply do some error checking before trying to calculate the
function, and skip it altogether when A = B = 0.

Mike


Post a reply to this message

From: Penelope20k
Subject: Re: What... the hell...?
Date: 11 Jun 2007 11:14:34
Message: <466d66da$1@news.povray.org>





news:441ea0bb@news.povray.org...
> >>"atan2(A,B): Arc-tangent of (A/B). Returns the angle, measured in
> >>radians, whose tangent is (A/B). Returns appropriate value even if B is
> >>zero. Use atan2(A,1) to compute usual atan(A) function."
> >
> >
> >>Um... yeah, OK... so why does atan2(0, 0) give we a fatal parse error?
> >
> >
> >   Because the result is not defined. You are basically asking the
> > direction of a zero vector, which has none.
>
> I just thought the whole point of using atan2 was to _avoid_ divide by
> zero errors.
>
> Sure, if the vector has a length of zero it has no defined direction.
> OTOH, I would imagine in most cases it just wouldn't *matter* what
> number the function returns in this case - just so long as it returns
> something, rather than an error...
>
> Oh well.


Post a reply to this message

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