POV-Ray : Newsgroups : povray.general : Understanding isosurface, difference between negative and positive : Re: Understanding isosurface, difference between negative and positive Server Time
28 Jul 2024 22:30:10 EDT (-0400)
  Re: Understanding isosurface, difference between negative and positive  
From: clipka
Date: 5 Jan 2014 01:42:12
Message: <52c8fec4$1@news.povray.org>
Am 05.01.2014 02:23, schrieb Louis:
> Doctor John <j.g### [at] gmailcom> wrote:
>> On 28/12/13 16:39, Louis wrote:
>>>
>>> Thanks! that cleared it up! I looked over the fact that squared dimensions are
>>> always positive. Ouch.
>>>
>>
>> We've all done it (or something similar)
>>
>> John
>> --
>> Protect the Earth
>> It was not given to you by your parents
>> You hold it in trust for your children
>
> I must be doing something similar again, I've spent some hours looking, but I
> can't spot my error:
>
> // Rotate a position 1 km above earths surface to some coordinate
> #declare test=vrotate(<0,0,-6372>, <35.201352,111.639249,0>);
>
> #debug concat("position = <",str(test.x,0,3),
> ",",str(test.y,0,3),",",str(test.z,0,3), ">\n")
>
> #debug
> concat("height=",str(pow(pow(test.x,3)+pow(test.y,3)+pow(test.z,3),(1/3)),0,3),
> "\n") // This should be 6372, rotating about the origin <0,0,0>
>
> The result is:
> position = <-4839.809,3673.150,1920.052>
> height=-1.#IO
>
> I'm not sure why height is printed out like that (-1.#IO), is it trying to use
> imaginary numbers?

No; the "-1.#IO" is probably a failed attempt to round either "-1.#INF" 
or "-1.#IND" to 3 fractional digits. Printing the height to a precision 
of at least 4 fractional digits should give you more information (you 
can specify "-1" as the number of fractional digits to let POV-Ray decide).

> Any way, if I calculate it on a calculator:
>
> cube(4839.809) + cube(3673.15) + cube(1920.052) = 170003198137.853207737
> cuberoot(170003198137,853207737) = 5539,6929949498910498665819311567

Note that you're not doing exactly the same thing, as you're dropping 
the sign of the first value. As you're raising it to a power of 3, the 
sign is kept. Moreover, the sum of all three cubes is also negative.

POV-Ray's implementation of pow() is based on the standard C math 
library, which doesn't like raising a negative value to the power of any 
non-integer, even if the exponent is the reciprocal of an integer (not 
to mention that the binary floating-point representation of 1/3 isn't 
exactly 1/3 due to rounding).


> So how did my altitude get burried down under the earths crust in hot lava? I'd
> expect the length of the vector to stay 6372, regardless of how it rotates.
>
> Am I misunderstanding vrotate?

No, but you're misunderstanding distance computations in 3D space ;-)

You probably thought that with distance computations in 2D space using 
squares and square roots, 3D space would call for cubes and cubic roots, 
but this is not the case at all; the proper formula should indeed be:

   #declare length = sqrt(pow(test.x,2)+pow(test.y,2)+pow(test.z,2));

or, even simpler yet (and less prone to errors ;-)):

   #declare length = vlength(test);


Post a reply to this message

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