POV-Ray : Newsgroups : povray.binaries.images : Hollow sphere, filled with shperes : Re: Hollow sphere, filled with shperes Server Time
30 Jul 2024 02:26:05 EDT (-0400)
  Re: Hollow sphere, filled with shperes  
From: Trevor G Quayle
Date: 25 Jan 2013 14:05:00
Message: <web.5102d6cfb194634781c811d20@news.povray.org>
"Lars R." <rou### [at] gmxnet> wrote:
> 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?
>
>      Lars R.

I don't have the maths for you but the general concept is this:

When testing for the intersection of spheres, you are really testing if the
centers of the spheres are at least 'x' distance from each other where 'x' = the
sum of the two radii.  Now you can extend this to cubes, but the difficulty is
deterning the 'x' value as it is not constant.

You need to:
1) determine the direction vector between the two cubes
2) determine the local rotations of the cubes relative to the direction vector
from 1)
3) determine the distances to the surfaces of the two cubes from their centers
along that direction vector.
4) ensure the sum of these two lengths is less than the total distance between
the centers.

Yes it's that simple!

-tgq


Post a reply to this message

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