POV-Ray : Newsgroups : povray.newusers : Volume and Area Calculations in POV-Ray ? : Re: Volume and Area Calculations in POV-Ray ? Server Time
30 Jul 2024 04:19:58 EDT (-0400)
  Re: Volume and Area Calculations in POV-Ray ?  
From: Hans-Werner
Date: 25 Sep 2004 11:35:01
Message: <web.41558ec6ea4355ba86e5b6190@news.povray.org>
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.



Thank you in advance



#include "colors.inc"

#declare E = 2.71828;

#declare IsoFinish =
finish {
 ambient 0 diffuse 1
 specular 1 roughness 0.02
 brilliance 2
}


/*
#declare isocylinder =
isosurface
{
 function {sqrt(x*x + y*y) - 0.5}
 threshold 0
 contained_by {box {<-1,-1,-1>, < 1, 1, 1>}}
 texture
 {
  pigment {color Red}
  finish {IsoFinish}
 }
 translate < 1, 2, 0>
}

#declare isoepsilon =
isosurface
{
    function { y-pow(E, -(x*x+z*z)) }
    max_gradient 1.4
    accuracy 0.02
    contained_by{box{<-2,0,-2><2,1,2>}}
}
*/

#declare THING = difference
{

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>}}
}

isosurface
{
 function {sqrt(y*y + z*z) - 0.2}
 threshold 0
 contained_by {box {<-1,-1,-1>, < 1, 1, 1>}}
 texture
 {
  pigment {color Red}
  finish {IsoFinish}
 }
 translate < 0, 0.5, 0>
}

}


//-----------------
// Create the shape
/*
#declare E = 2.71828;
#declare THING = difference
{
  isosurface {
    function { y-pow(E, -(x*x+z*z)) }
        max_gradient 1.4
        contained_by{box{<-2,0,-2><2,1,2>}}
    }

  cylinder {-x*2,x*2,0.2}
}
*/




// ----------------------------------------
// 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>}
object
{ THING
  pigment {rgb .9}
  finish {phong 0.5 phong_size 10}
}

// ----------------------------------------
// Set the range over which to iterate

#declare Xmin = min_extent(THING).x;
#declare Xmax = max_extent(THING).x;
#declare Zmin = min_extent(THING).z;
#declare Zmax = max_extent(THING).z;

// ----------------------------------------
// Trace the rays

#declare Norm = <0,0,0>;
#declare Total=0;
#declare Step = 0.05; // Set smaller for more accuracy
#declare X=Xmin;
#while (X<Xmax)
  #declare Z=Zmin;
  #while (Z<Zmax)
    #declare P1=trace(THING, <X,100,Z>, -y);
    #declare P2=trace(THING, <X,-100,Z>, y, Norm);
    // Test to see if the trace hit anything
    #if (vlength(Norm)>0)
      #declare Total = Total + P1.y - P2.y;
    #end
        #declare Z=Z+Step;
  #end
  #declare X=X+Step;
#end

//------------------------------------------
// Calculate the volume

#declare Volume = Total*Step*Step;
#debug concat ("Volume = ", str(Volume,-1,-1), " cubic POV unitsn")


Post a reply to this message

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