# Describing the spherical cap intersection between a spherical shell and a solid ball

I have:

• an infinitely thin sphere shell with center O1 and radius R1, and
• a solid ball with center O2 and radius R2

Now i need a way to describe their intersection.

For example, for 2 spheres (shells), the intersection is a circle, and I can find the equation (the mathematical description) of that circle.

For the sphere and ball i know the intersection is a spherical cap, but I don't know if it is possible to find its analytical or algebraic expression.

I can determine the base (outer circle) of the spherical segment, using the sphere-sphere intersection math described here .

But how would I extend that to the full dish/bowl shape of the spherical cap?

• static or dynamic? – Bálint Sep 12 '17 at 11:15
• mathworld.wolfram.com/Sphere-SphereIntersection.html is that what are you looking for? – Nick Sep 12 '17 at 11:19
• I still don't understand how a ball is different from a sphere. From a geometrical point of view, these seem synonymous. – Philipp Sep 12 '17 at 14:30
• @Philipp, a sphere is the set of points on the surface of a ball. The ball can be an open ball or a closed ball. – Mag Sep 12 '17 at 14:49
• whoops, here are differences between sphere and ball (for people like me who didn't know this) In topology, a “ball” refers to the space inside a (topological) sphere, whereas “sphere” refers to the surface only. Source: quora.com/Whats-the-difference-between-a-ball-and-a-sphere – Nick Sep 12 '17 at 17:00

If the distance between the center of the 2 hyperspheres is less than 2 times the radius of them, then they intersect.

So, if the points are defined like this: (x1, y1, z1, w1), (x2, y2, z2, w2) then the intersection check is

√((x1 - x2)² + (y1 - y2)² + (z1 - z2)² + (w1 - w2)²) < 2 * radius

• Well, but how can i get the math description of the intersection? – Mag Sep 12 '17 at 11:33
• @Mag What do you mean by "math description"? – Bálint Sep 12 '17 at 12:21
• I mean the mathematical expression (equation, inequation or other) of the intersection zone if it's possible. – Mag Sep 12 '17 at 12:32
• @Mag How about you edit your question with an actual description of what you're trying to achieve before asking for the mathematical formula. We might be able to help you with a better understanding of the problem at hand. – Tom 'Blue' Piddock Sep 12 '17 at 12:55
• @Mag - don't tell me in the comments edit your question. – Tom 'Blue' Piddock Sep 12 '17 at 13:57

This follows pretty directly from the sphere-sphere formulas in my earlier answer, so I won't repeat the full breakdown here.

Once you've verified that the sphere and ball surfaces do intersect, you can use those formulas to find the radius of the circular intersection r_i and the signed proportion of the distance to the intersection plane h:

Next we can form a vector pointing to the center of the sphere cap, call it peak:

peak = normalize(c2 - c1)


The cap has an angular extent phi_max, measured in radians from the peak of the cap to the outer rim. We can find it using the 2-argument arctangent function:

phi_max = atan2(r_i, hd)


Now if we augment peak with two more mutually perpendicular unit vectors u and v to form a 3D basis (or equivalently, a transformation matrix) we can express any point in the spherical cap like so:

0 <= theta < 2pi
0 <= phi <= phi_max

point = c_1 + r_1 * (
peak * cos(phi)
+ u * sin(phi) * cos(theta)
+ v * sin(phi) * sin(theta)
)


If the sphere is fully contained in the ball, then you can pick any arbitrary basis vectors and choose phi_max = pi to express the entire surface using this same parametrization.

Extending this to 4-dimensional space is hard to picture, but the math follows a similar pattern with a fourth orthonormal basis vector w:

0 <= theta <= 2pi
0 <= beta <= pi
0 <= phi <= phi_max

point = c+1+ r_1 * (
peak * cos(phi)
+ u * sin(phi) * sin(beta) * cos(theta)
+ v * sin(phi) * sin(beta) * sin(theta)
+ w * sin(phi) * cos(beta)
)


You can confirm that for any value of point, (point - c_1)^2 = r_1^2 and (point - c_2)^2 <= r_2^2

In the same way that in the 3D case, the spherical cap can be thought of as a series of nested circles, varying in radius from a point at the peak of the cap to the outer rim; in 3D we can think of the hyperspherical cap as a series of nested spheres.

• Thank you very much @DMGregory That is what i search. I want to know what will change for the hypersphere and hyperball? – Mag Sep 13 '17 at 20:54
• That's a new question, and one that might be better to ask on the Math StackExchange. Games in 4+ dimensional spaces exist, but are somewhat rare, so you'll find hyperspherical expertise a bit sparse here. ;) – DMGregory Sep 13 '17 at 21:24
• OK @DMGregory, thank you. Your answer is the better one i found. – Mag Sep 13 '17 at 21:40
• Please, tell me, if i need the spherical cap intersection between a spherical shell and two solid balls, if i understand well, only the phi_max = min (phi_max1, phi_max2) and the peak can be any of peak1 or peak2. Right? – Mag Sep 14 '17 at 11:13
• Again, that's a different question. We don't use comments like a discussion thread here, so make a new question post if you need something else. If you want to intersect one spherical cap with another ball, the result might no longer be a spherical cap, but a lens shape like the skin on an apple slice. So you might need a different parameterization. – DMGregory Sep 14 '17 at 11:17