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