|
|
Wasn't it Hans-Werner who wrote:
>First, thank you for your help.
>My problem is:
>I want to translate the tunnel (the cylinder) along the y-axis.
>A translation of the cylinder inside the #declare THING does not work.
>the CSG object cylinder or an isosurface.
The problem that you're seeing with the rendered image is because you
need a higher max_trace (or all_intersections). NB Don't confuse this
with the similarly named max_trace_level, that's something completely
different.
A CSG cylinder will do the job just as well and will render and trace()
faster because POV can solve directly for the point where the ray hits
the surface rather than having to hunt for it with a series of guesses.
My tracing code assumed a convex object, it only looks for the first and
last surface it encounters when looking downwards. The easiest way to
fix this is to calculate the volume of the outside part and the volume
of the hole separately and then subtract one from the other.
#include "colors.inc"
#declare E = 2.71828;
#declare IsoFinish =
finish {
ambient 0 diffuse 1
specular 1 roughness 0.02
brilliance 2
}
#declare THING1 = isosurface
{
function { y-pow(E, -(x*x+z*z)) }
max_gradient 1.4
accuracy 0.01
contained_by{box{<-2,0,-2><2,1,2>}}
all_intersections
}
#declare THING2 = intersection {
object {THING1}
cylinder {<-3,0,0><3,0,0>,0.2 translate <0, 0.5, 0>}
}
// ----------------------------------------
// This bit is so that you can check that the
// THING is the shape that you expected it to be.
// It's not necessary for the volume calculation
camera { location <3, 1, -4> look_at <0, 0, 0> angle 50}
light_source {<-100,200,-100> colour rgb <0.9, 0.9, 1.0>}
difference {
object{ THING1
pigment {rgb .9}
finish {phong 0.5 phong_size 10}
}
cylinder {<-3,0,0><3,0,0>,0.2 translate <0, 0.5, 0>
texture {
pigment {color Red}
finish {IsoFinish}
}
}
}
// ----------------------------------------
// Set the range over which to iterate
// Remember that THING1 is the bigger one
#declare Xmin = min_extent(THING1).x;
#declare Xmax = max_extent(THING1).x;
#declare Zmin = min_extent(THING1).z;
#declare Zmax = max_extent(THING1).z;
// ----------------------------------------
// Trace the rays
#declare Norm = <0,0,0>;
#declare Total1=0;
#declare Total2=0;
#declare Step = 0.05; // Set smaller for more accuracy
#declare X=Xmin;
#while (X<Xmax)
#declare Z=Zmin;
#while (Z<Zmax)
// Trace THING1
#declare P1=trace(THING1, <X,100,Z>, -y);
#declare P2=trace(THING1, <X,-100,Z>, y, Norm);
// Test to see if the trace hit anything
#if (vlength(Norm)>0)
#declare Total1 = Total1 + P1.y - P2.y;
#end
// Trace THING2
#declare P1=trace(THING2, <X,100,Z>, -y);
#declare P2=trace(THING2, <X,-100,Z>, y, Norm);
// Test to see if the trace hit anything
#if (vlength(Norm)>0)
#declare Total2 = Total2 + P1.y - P2.y;
#end
#declare Z=Z+Step;
#end
#declare X=X+Step;
#end
//------------------------------------------
// Calculate the volume
#declare Volume1 = Total1*Step*Step;
#declare Volume2 = Total2*Step*Step;
#debug concat ("Outer volume = ", str(Volume1,-1,-1),
" cubic POV units\n")
#debug concat ("Inner volume = ", str(Volume2,-1,-1),
" cubic POV units\n")
#debug concat ("Volume = ", str(Volume1-Volume2,-1,-1),
" cubic POV units\n")
Post a reply to this message
|
|