POV-Ray : Newsgroups : povray.general : Odd behavior of 1/sqrt functions in iso_surface : Odd behavior of 1/sqrt functions in iso_surface Server Time
3 Aug 2024 10:23:06 EDT (-0400)
  Odd behavior of 1/sqrt functions in iso_surface  
From: Richard Kline
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

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