|
|
Let the sphere be |X - C|^2 = r^2 and the plane n * X = d. We first need to determine whether the sphere and plane intersect. distCenter = abs(n * C - d) is the distance from the sphere center to the plane. The following cases can occur: - abs(n * C - d) > r The plane does not intersect the sphere. - abs(n * C - d) < r The plane intersects the sphere. The minimum distance is 0 naturally and we need to determine any one of the infinite number of points of intersection. If the plane does not intersect the sphere, we need to determine the point on the hollow sphere that is closest to the plane. That point is P = C - sign(n * C) * r * n. where n * C is the dot product of the plane normal and the sphere center, of which the sign determines the side of the plane the sphere center is located. If the sign is negative, the center is located on the negative side of the plane (where the negative normal points to), otherwise it is located on the positive side of the plane. Now we can determine the distance between the point P and the plane as dist = abs(n * P - d) = abs(n * C - d) - radius. If the plane intersects the sphere, the intersecting shape is a circle characterized by |X - B|^2 = e^2 where the circle center B = C - sign(n * C) * distCenter * n and e = sqrt(r^2 - distCenter^2). Additionally the circle must be part of the plane, therefore n * (X - B) = 0. To get a point on the circle, we calculate any two points on the plane (that don't necessarily have to be part of the circle), take the normalized difference vector D of these two points, and put a line through the circle center B and calculate B + e * D which must be a point on the circle. We already have B as point of the plane. To get another point of the plane, let B = (b1, b2, b3) then A = (b1 + 1, b2, (d - n1*(b1+1) - n2*b2) / n3) must be another point on the plane that is different from B. If n3 = 0, then the new point A can be determined as A = (b1, b2, b3 + 1). Now let D = (A - B) / |A - B|, the normalized direction vector from B to A, then B + e * D is a point on the circle of intersection between the plane and the sphere.
|
Copyright © by Martin Ecker |