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: Chris Kinata
Date: 23 Sep 2005 16:45:47
Message: <4334697b$1@news.povray.org>
Hi Mike,

Thanks, really cool...

So in your code, we're:

-- Scanning over the xy plane, shooting rays parallel
to the z-axis, down from above and up from below.

-- If the z-values of the intersection points returned
are equal, the object has no thickness at that xy coordinate.
If they're both 0, there was no intersection, or the object
coincides with the xy plane at that point.

I can use this to code a macro that takes an object and a
step increment, and then uses its extents to find what part
of the xy plane to scan, and returns the estimated volume.

Maybe at some point I could add code that sort of recursively
continues a scan ray through the object, testing whether a
given surface-to-surface vector is inside or outside. This would
permit estimating the volume of concave objects.

Regards,
Chris

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