I have an axis alligned 3D box (cuboid), and a sphere at each of its vertices (each with different radius). How can I check if all points of the box are covered by any of the spheres?
I need an algorithm that is rather fast, and not necessarily exact. False negatives -- that is saying that the box is not covered when in fact it is -- are not a big problem, but still I would like to minimise this kind of errors. False positives are unacceptable.
Intended use is calculating volume of an object specified by a signed distance function. I'm recursively dividing space and if a given box is completely outside or inside of the object, I know I can stop recursion on this level. False negative would cause extra splitting of the box, but not an error in the result.
Corrugated cardboard can't be formed into a sphere (it was specifically designed not to be able to warp), so these spheres would have to be made from another material. Styrofoam and plastic would be extremely unsustainable. Actual wood would be difficult to form into spheres.
If s is the side length of the cube, we have that Vcube=s3. Notice that the largest possible sphere that can fit inside the cube is the inscribed sphere, which has radius 12s. Using the volume formula for a sphere, we find that Vsphere=43πr3=43πs38=π6s3.
In a cube of 2x2x2 cm cube, we can fit one sphere. There are ( 20 x 20 x 20) / ( 2 x 2 x2) = 1000 cubes or spheres. Diameter of the sphere is 2 cm. In 20 cm side we can place 10 spheres .
(While I'm trying to find a geometrically optimal version, here's a simple idea that's sure to work, but it may return some false negatives.)
Consider two spheres at diagonally opposite corners of the box. Each of the spheres has 3 or more points where it intersects with the edges of the box. Seen from the opposite corner, one of these points is the furthest point inside the box on the sphere. That means that if all these points are covered by the opposite sphere, then the whole box is covered by these two spheres.
example 1: all points covered by diagonally opposite sphere
If the two spheres don't cover the whole box, check the other 3 pairs of diagonally opposite spheres. If one of the pairs covers the box, then it is covered by the 8 spheres. If none of the pairs covers the box, then it may or may not be covered by the 8 spheres (possible false negative).
example 2: some points not covered by diagonally opposite sphere
In the specific case of a cubic box, the radius of two diagonally opposite spheres which cover the whole cube with size 1 is given by these formulas:
0 ≤ ra ≤ 1 → rb ≥ √(2 + (1 - ra)2)
1 ≤ ra ≤ √2 → rb ≥ √(1 + (1 - √(ra2 - 1))2)
√2 ≤ ra ≤ √3 → rb ≥ 1 - √(ra2 - 2)
To avoid time-consuming calculations, using linear interpolation between a few points (including the breakpoints at 1 and √2) will give a conservative approximation. Or you can use the simpler but less precise approximation of ra2 + rb2 ≥ 3 (the blue circle on the graph below).
There is a similar method where you consider the 4 spheres around the bottom corners of the box, find the "landscape" their surfaces create inside the box, and then find the lowest point in this "landscape". If you then do the same for the top spheres, and the minimum heights of the two landscapes sum to more than the height of the box, then the box is covered by the spheres.
You can then also check the left/right and front/rear minimum heights to see whether they add up to the width and depth of the box. If any of them do, then the box is covered by the spheres. If none does, it is unsure whether the box is covered (possible false negative). Since this method considers all the spheres at once, I think it'll give fewer false negatives than the diagonally-opposite spheres method.
example 3a: finding the intersections of the 4 spheres
Seen from above, the intersection between any two spheres is the line between the two intersecting points of the circles where the spheres intersect the bottom side of the box.
example 3b: finding the lowest points on the intersections
The intersections between spheres join up to form the "valleys" in the "landscape". The highest point of a valley between two neighbouring spheres is at the edge of the box, the highest point of a valley between two diagonally opposite spheres is on the diagonal between their centers. So the lowest points are where the "valleys" meet. Which of these points is the lowest, is determined by their distance to the diagonal between the centers of the two largest spheres.
example 3c: side not completely covered
If some of the "valleys" don't meet, then part of the bottom side is not covered by these 4 spheres, and the minimum height is obviously zero.
I've been fiddling around with code for the minimum-height method, and the geometry needed to calculate the lowest point between 4 spheres is actually quite simple:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With