Find if sphere is inside parallelepiped

467 Views Asked by At

I have many spheres in a 3D space, with their center's position and their radius to be known. I also have 1 parallelepiped ( wiki link) with its 8 vertices' positions to be also known.

How can I check if any of the spheres is "touching" or is inside (partly or whole) the parallelepiped or is completely out of the parallelepiped ?

If anybody can help I would be thankful.

Thanks.

1

There are 1 best solutions below

9
On

The question is actually asking the distance of a point (center) to several (6) planes, which is intuitively defined by the length of line segment from the point to the plane which is perpendicular to the plane. After rephrasing the question will be very easy if you know vector.

Since you know the coordinate of vertices, to find the distance of center of sphere to faces of parallelepiped, pick vertices that are in the same face and find 2 vectors on this face (which will be edges or diagonals of a face). Compute the cross product and you will get the normal vector to this face. Find the line through the center of the sphere parallel to the normal and find the point intersected by this line and the face. Find the distance of this intersection and the center of sphere and compare to radius. You have to check for all 6 faces then done.