POV-Ray : Newsgroups : povray.text.scene-files : A Volume Macro! Server Time
23 Dec 2024 14:58:22 EST (-0500)
  A Volume Macro! (Message 1 to 1 of 1)  
From: Greg M  Johnson
Subject: A Volume Macro!
Date: 10 Sep 2000 20:37:27
Message: <39bc2947@news.povray.org>
#macro Volume(MyObject,interval,bailout,Accuracy)
        //interval is starting # of partitions, start with small number,
say 5
        //bailout is number of iterations to try before giving up, try
10
        //Accuracy is the fractional delta between sucessive estimations
of volume, try 0.01.
        #debug "\n"
        #debug "count interv error   volume"
        #debug "\n"
        #local oldvol=0;
        //#declare bailout=100;
        //#declare Accuracy=0.01;

        #local MaxExt=max_extent(MyObject);
        #local MinExt=min_extent(MyObject);
        #local minx=MinExt.x;
        #local miny=MinExt.y;
        #local minz=MinExt.z;
        #local maxx=MaxExt.x;
        #local maxy=MaxExt.y;
        #local maxz=MaxExt.z;
        #declare obfun=pigment {object {MyObject color Black color
White}}

        #local ntries=1;
        #while (ntries<bailout)

                #local summy=0;
                #local dx=(maxx-minx)/interval;
                #local dy=(maxy-miny)/interval;
                #local dz=(maxz-minz)/interval;
                #local ix=0;
                #while(ix<interval)
                        #local iy=0;
                        #while(iy<interval)
                                #local iz=0;
                                #while(iz<interval)

                                        #local
blank=eval_pigment(obfun,<minx+(ix+0.5)*dx,miny+(iy+0.5)*dy,minz+(iz+0.5)*dz>);

                                        #local summy=summy+blank.x;

                                #declare iz=iz+1;
                                #end
                        #declare iy=iy+1;
                        #end
                #declare ix=ix+1;
                #end

                #declare newvol=summy*dx*dy*dz;

                #local try=abs((newvol-oldvol)/newvol);

                #debug str(ntries,3,0)
                #debug "  "
                #debug str(interval,6,0)
                #debug "  "
                #debug str(try,3,4)
                #debug "  "
                #debug str(newvol,3,4)
                #debug "\n"

                #if(try <Accuracy & ntries>2)
                        #local ntries=ntries+2*bailout;
                #else
                        #local interval=int(interval*1.5);
                        #declare oldvol=newvol;
                #end
        #declare ntries=ntries+1;
        #end
newvol
#end

//-----END OF MACRO, EXAMPLE OF USE--------------

#declare  MyObject=difference{sphere{0,1}sphere{0,0.5}}

#declare ell=Volume(MyObject,4,10,.001)


Post a reply to this message

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