POV-Ray : Newsgroups : povray.general : How find the volume of an object? : Re: How find the volume of an object? Server Time
1 Aug 2024 12:25:21 EDT (-0400)
  Re: How find the volume of an object?  
From: Mike Williams
Date: 22 Sep 2005 00:43:49
Message: <TUGn6AAXSjMDFwl3@econym.demon.co.uk>
Wasn't it Chris Kinata who wrote:
>Hi all...
>
>[Reposted from mistaken thread in povray.programming]
>
>What is the best method in POV-Ray for finding the
>volume of a simple convex (that is, no hollows or cavities)
>object that is the intersection of two other objects?
>
>One way might be to iteratively intersect this object
>with a series of long thin boxes incremented
>along (for example) the xy plane, and use the Extents macro
>in shapes.inc to get the length of the box. Summing these
>box volumes would return a total volume slightly larger
>than the real volume.

The Extents macro won't help. It will return the full length of the box
rather than just the portion that intersects the target object. 

I'd suggest using trace() in the same sort of way. Use trace to find the
two points where the midline of the long thin box intersects the surface
and multiply the distance between them by the cross section area of the
(now imaginary) box.

Here's a quick test with a sphere. I've used a sphere because I know
what the actual result should be. 

#declare THING = sphere {0,1}

#debug concat("Actual volume = ", str(4/3 * pi,-1,-1), "\n")

#declare Step = 0.01;
#declare Area = Step*Step;

#declare Vol = 0;

#declare X=-1;
#while (X<1) 
  #declare Y=-1;
  #while (Y<1)
    #declare P1 = trace(THING, <X,Y,1000>, -z);
    #declare P2 = trace(THING, <X,Y,-1000>, z);
    #declare Vol = Vol + (P1.z - P2.z)*Area;
    #declare Y = Y + Step;
  #end
  #declare X = X + Step;
#end

#debug concat("Calculated volume = ", str(Vol,-1,-1), "\n")

Shooting 10000 pairs of rays gives four figure accuracy.
     

-- 
Mike Williams
Gentleman of Leisure


Post a reply to this message

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