POV-Ray : Newsgroups : povray.binaries.images : Hollow sphere, filled with shperes : Re: Hollow sphere, filled with shperes Server Time
30 Jul 2024 02:29:24 EDT (-0400)
  Re: Hollow sphere, filled with shperes  
From: clipka
Date: 26 Jan 2013 08:56:51
Message: <5103e0a3$1@news.povray.org>
Am 25.01.2013 14:52, schrieb Lars R.:
> I wrote a C++ program that generates the scene you see in the attached
> image. (40k non-intersecting spheres)
>
> Now I'd like to change it to use many,many small cubes (randomly
> rotated, of course), so I need an intersection formula for cubes.
>
> I tried something like this: If one of the 8 corners of a cube is inside
> the other one than the cubes intersect:
>
> |  for corner = cubeA.corner0 … cubeA.corner7:
> |     if( corner is_inside_of cubeB ) return true;
> |
> |  for corner = cubeB.corner0 … cubeB.corner7:
> |     if( corner is_inside_of cubeA ) return true;
>
> But it is possible that 2 cubes intersects even if none of the corners
> is inside of the other cube. :-(
>
> Has anyone a better formula for me?

Not a formula, but an algorithm:

(0) [optional, just for speed] If the cubes' bounding boxes don't 
intersect, the cubes don't intersect.

(1) If any corner of the smaller cube is inside the larger cube, they 
intersect. (No need to test the other way round.)

(2) If any edge of the smaller cube intersects any surface of the larger 
cube, they intersect. (Again no need to test the other way round.)

(3) In any other case, they don't intersect.


Note that this only works for cubes, not for generic boxes.


Post a reply to this message

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