POV-Ray : Newsgroups : povray.general : Odd behavior of 1/sqrt functions in iso_surface Server Time
3 Aug 2024 12:14:03 EDT (-0400)
  Odd behavior of 1/sqrt functions in iso_surface (Message 1 to 7 of 7)  
From: Richard Kline
Subject: Odd behavior of 1/sqrt functions in iso_surface
Date: 9 Mar 2004 02:22:17
Message: <404d70a9@news.povray.org>
When I attempted to render the gravitation equipotential surface of two 
bodies (i.e the surfaces of the double planet in Robert Forward's 
"Flight of the Dragonfly"). The iso_surface object behaved oddly with 
these three behaviors:

1) If the contained_by shape is larger than the true surface for the 
given threshold value, the entire contained_by shape (either box or 
sphere) is rendered as part of the surface.

2) If parts of the surface extend beyond the contained_by shape, you get 
the difference of the contained_by shape and the true surface. (this is 
shown in POVRay Example 1 below)

3) If the contained_by shape is made large enough to contain the true 
surface, camera, and light_source, you get the correct results for the 
iso_surface, but it takes a long time to render since every point in the 
scene has to be tested.



Since the Gravitational potential is a function of 1/r the function used 
is 1/sqrt(x*x+y*y+z*z)

To test where this behavior originates, I did 3 other test files (shown 
in Examples 2, 3, and 4 below) which should have all produced the same 
result, a sphere of radius 4.47214 (i.e. sqrt(20.0)), with the following 
results

Example 2: the function was x*x+y*y+z*z, threshold 20.0
Result: Worked with the proper max_gradient

Example 3: the function was sqrt(x*x+y*y+z*z), threshold 4.47214
Result: Worked with the proper max_gradient

Example 4: the function was 1/(sqrt(x*x+y*y+z*z)+0.0001), threshold 0.22361
Result: Behavior like Example 1, regardless of max_gradient, in fact for 
the case where the contained_by shape is larger than the expected 
surface, random values of max_gradient make no difference and no value 
is printed in the messages so the test of the function is apparently not 
taking place.


I've tested this with both linux and Windows versions of POVRay 3.5 with 
the same results so it appears to be something pathological in the code 
when the function involves 1/sqrt.  Does anyone have any insight into this?


Richard Kline




//Begin Example 1
#include "shapes.inc"
#include "shapes2.inc"
#include "colors.inc"
#include "textures.inc"

camera {
         location <0.0, 120.0, -75.0>
         up < 0.0, 1.0, 0.0>
         right < 4/3, 0.0, 0.0>
         look_at <5,30.0,0>
         angle 60
}

light_source { <25.0, 200.0, -80.0> color White}

#declare Roche = function {
10.0/(sqrt(x*x+y*y+z*z)+0.000001) +
10.0/(sqrt((x+20)*(x+20)+y*y+z*z)+0.000001)}

plane { y,-20
pigment { hexagon pigment {Red}, pigment {Gray50}, pigment {Blue} scale 10}
}
isosurface {
         function { Roche(x,y,z) }
         contained_by { box {<-15,-5,-5>,<-5,5,5>} }
         threshold 2.0
         max_gradient  84

         texture {pigment {Green} finish {Dull}}
         scale <4.5,4.5,4.5>
         translate <30,25,0>
// Rotations to show the difference shape
         rotate <0,90,0>
         rotate <30,0,0>
}
//End Example 1


//Begin Example 2
#include "shapes.inc"
#include "shapes2.inc"
#include "colors.inc"
#include "textures.inc"

camera {
         location <0.0, 120.0, -75.0>
         up < 0.0, 1.0, 0.0>
         right < 4/3, 0.0, 0.0>
         look_at <5,30.0,0>
         angle 60
}

light_source { <25.0, 200.0, -80.0> color White}

#declare Sphere1 = function {
         x*x + y*y + z*z }

plane { y,-20
pigment { hexagon pigment {Red}, pigment {Gray50}, pigment {Blue} scale 10}
}

isosurface {
         function {Sphere1(x,y,z)}
         contained_by { box {<-6,-6,-6>,<6,6,6>}}
         threshold 20.0
         max_gradient 16.0
         texture {pigment {Green} finish {Dull}}
         scale <4.5,4.5,4.5>
}
//End Example 2


//Begin Example 3
#include "shapes.inc"
#include "shapes2.inc"
#include "colors.inc"
#include "textures.inc"

camera {
         location <0.0, 120.0, -75.0>
         up < 0.0, 1.0, 0.0>
         right < 4/3, 0.0, 0.0>
         look_at <5,30.0,0>
         angle 60
}

light_source { <25.0, 200.0, -80.0> color White}

#declare Sphere2 = function {
         sqrt(x*x + y*y + z*z) }


plane { y,-20
pigment { hexagon pigment {Red}, pigment {Gray50}, pigment {Blue} scale 10}
}

isosurface {
         function {Sphere2(x,y,z)}
         contained_by { box {<-6,-6,-6>,<6,6,6>}}
         threshold 4.47214
         max_gradient 1.0
         texture {pigment {Green} finish {Dull}}
         scale <4.5,4.5,4.5>
}
//End Example 3


//Begin Example 4
#include "shapes.inc"
#include "shapes2.inc"
#include "colors.inc"
#include "textures.inc"

camera {
         location <0.0, 120.0, -75.0>
         up < 0.0, 1.0, 0.0>
         right < 4/3, 0.0, 0.0>
         look_at <5,30.0,0>
         angle 60
}

light_source { <25.0, 200.0, -80.0> color White}

//The +0.0001 in the denominator of the function is to ensure no
// possibility of a divide by zero occurring
#declare Sphere3 = function {
         1.0/(sqrt(x*x + y*y + z*z)+0.0001) }

plane { y,-20
pigment { hexagon pigment {Red}, pigment {Gray50}, pigment {Blue} scale 10}
}

isosurface {
         function {Sphere3(x,y,z)}
         contained_by { box {<-6,-6,-6>,<6,6,6>}}
         threshold 0.22361
         max_gradient 100.0
         texture {pigment {Green} finish {Dull}}
         scale <4.5,4.5,4.5>
}
//End Example 4


Post a reply to this message

From: Mike Williams
Subject: Re: Odd behavior of 1/sqrt functions in iso_surface
Date: 9 Mar 2004 02:55:41
Message: <J5vaSSAyhXTAFwx9@econym.demon.co.uk>
Wasn't it Richard Kline who wrote:
>
>When I attempted to render the gravitation equipotential surface of two 
>bodies (i.e the surfaces of the double planet in Robert Forward's 
>"Flight of the Dragonfly"). The iso_surface object behaved oddly with 
>these three behaviors:
>
>1) If the contained_by shape is larger than the true surface for the 
>given threshold value, the entire contained_by shape (either box or 
>sphere) is rendered as part of the surface.
>
>2) If parts of the surface extend beyond the contained_by shape, you get 
>the difference of the contained_by shape and the true surface. (this is 
>shown in POVRay Example 1 below)
>
>3) If the contained_by shape is made large enough to contain the true 
>surface, camera, and light_source, you get the correct results for the 
>iso_surface, but it takes a long time to render since every point in the 
>scene has to be tested.
>

I confess to not having tried all your examples, but what you describe
sounds exactly like rendering the isosurface inside out.

See <http://www.econym.demon.co.uk/isotut/insideout.htm>

The "inside" of an isosurface is the region where the function minus the
threshold is less than zero and the outside is where it's greater than
zero. For some functions this may be different from what common sense
tells you should be the inside and outside.

Try using "isosurface {function {0 - Roche(x,y,z) }" and 
"threshold -2.0" to flip the thing right side out.

-- 
Mike Williams
Gentleman of Leisure


Post a reply to this message

From: Christoph Hormann
Subject: Re: Odd behavior of 1/sqrt functions in iso_surface
Date: 9 Mar 2004 03:15:02
Message: <c2ju9u$21p$1@chho.imagico.de>
Richard Kline wrote:
> 
> Since the Gravitational potential is a function of 1/r the function used 
> is 1/sqrt(x*x+y*y+z*z)
> 
> [...]

You should note that the above function has a singularity at <0,0,0>. 
You should never expect such a function to render correctly if the 
singularity is inside the container (the fact that POV-Ray reports a 
finite maximum gradient does not mean anything here).

Christoph

-- 
POV-Ray tutorials, include files, Sim-POV,
HCR-Edit and more: http://www.tu-bs.de/~y0013390/
Last updated 07 Mar. 2004 _____./\/^>_*_<^\/\.______


Post a reply to this message

From: Lutz-Peter Hooge
Subject: Re: Odd behavior of 1/sqrt functions in iso_surface
Date: 9 Mar 2004 08:20:25
Message: <404dc499$1@news.povray.org>
Richard Kline <rkl### [at] earthlinknet> wrote:

> 1) If the contained_by shape is larger than the true surface for the 
> given threshold value, the entire contained_by shape (either box or 
> sphere) is rendered as part of the surface.

By default isosurfaces are solid objects, AFAIK every point where the 
function evaluates to something greater than zero is considered to be 
inside.
If you only care about the surface itself, you may want to use the 
'open' keyword. Or use the negative of the function to invert inside 
and outside.

> Since the Gravitational potential is a function of 1/r the function used 
> is 1/sqrt(x*x+y*y+z*z)

This is the function for a singularity. It might cause problems with the root 
solver, since it doesn't really have a maximum gradient.
In this case you might want to use the function for a hollow sphere with a 
radius of R instead. 
Thats is  1/r for r > R
          1/R for r <= R

Lutz-Peter


Post a reply to this message

From: Christopher James Huff
Subject: Re: Odd behavior of 1/sqrt functions in iso_surface
Date: 9 Mar 2004 09:09:28
Message: <cjameshuff-D426FF.09092809032004@news.povray.org>
In article <404d70a9@news.povray.org>,
 Richard Kline <rkl### [at] earthlinknet> wrote:

> Since the Gravitational potential is a function of 1/r the function used 
> is 1/sqrt(x*x+y*y+z*z)

Others have already mentioned the singularity problems at <x, y, z> = 0. 
In addition, gravitational fields have an inverse *square* falloff, 
1/r^2.

-- 
Christopher James Huff <cja### [at] earthlinknet>
http://home.earthlink.net/~cjameshuff/
POV-Ray TAG: <chr### [at] tagpovrayorg>
http://tag.povray.org/


Post a reply to this message

From: Mark Weyer
Subject: Re: Odd behavior of 1/sqrt functions in iso_surface
Date: 9 Mar 2004 11:38:39
Message: <404DF56C.2060900@informatik.uni-freiburg.de>
>>Since the Gravitational potential is a function of 1/r the function used 
>>is 1/sqrt(x*x+y*y+z*z)
> 
> In addition, gravitational fields have an inverse *square* falloff, 
> 1/r^2.

The (gradient) field does, yes. But the potential is of type 1/r.


-- 
merge{#local i=-11;#while(i<11)#local
i=i+.1;sphere{<i*(i*i*(.05-i*i*(4e-7*i*i+3e-4))-3)10*sin(i)30>.5}#end
pigment{rgbt 1}interior{media{emission x}}hollow}//  Mark Weyer


Post a reply to this message

From: Richard Kline
Subject: Re: Odd behavior of 1/sqrt functions in iso_surface
Date: 9 Mar 2004 22:15:25
Message: <404e884d@news.povray.org>
Mike Williams wrote:
> Wasn't it Richard Kline who wrote:
> 
>>When I attempted to render the gravitation equipotential surface of two 
>>bodies (i.e the surfaces of the double planet in Robert Forward's 
>>"Flight of the Dragonfly"). The iso_surface object behaved oddly with 
>>these three behaviors:
>>
>>1) If the contained_by shape is larger than the true surface for the 
>>given threshold value, the entire contained_by shape (either box or 
>>sphere) is rendered as part of the surface.
>>
>>2) If parts of the surface extend beyond the contained_by shape, you get 
>>the difference of the contained_by shape and the true surface. (this is 
>>shown in POVRay Example 1 below)
>>
>>3) If the contained_by shape is made large enough to contain the true 
>>surface, camera, and light_source, you get the correct results for the 
>>iso_surface, but it takes a long time to render since every point in the 
>>scene has to be tested.
>>
> 
> 
> I confess to not having tried all your examples, but what you describe
> sounds exactly like rendering the isosurface inside out.
> 
> See <http://www.econym.demon.co.uk/isotut/insideout.htm>
> 
> The "inside" of an isosurface is the region where the function minus the
> threshold is less than zero and the outside is where it's greater than
> zero. For some functions this may be different from what common sense
> tells you should be the inside and outside.
> 
> Try using "isosurface {function {0 - Roche(x,y,z) }" and 
> "threshold -2.0" to flip the thing right side out.
> 

Negating the function and threshold worked.  Thanks.  Also to the other 
respondents, I did add 0.0001 to the denominator of the function to 
avoid having a singularity.  I just didn't mention it up top.

Richard Kline


Post a reply to this message

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