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?

  • \$\begingroup\$ static or dynamic? \$\endgroup\$ – Bálint Sep 12 '17 at 11:15
  • \$\begingroup\$ mathworld.wolfram.com/Sphere-SphereIntersection.html is that what are you looking for? \$\endgroup\$ – Nick Sep 12 '17 at 11:19
  • 3
    \$\begingroup\$ I still don't understand how a ball is different from a sphere. From a geometrical point of view, these seem synonymous. \$\endgroup\$ – Philipp Sep 12 '17 at 14:30
  • 1
    \$\begingroup\$ @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. \$\endgroup\$ – Mag Sep 12 '17 at 14:49
  • 1
    \$\begingroup\$ 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 \$\endgroup\$ – 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
| improve this answer | |
  • \$\begingroup\$ Well, but how can i get the math description of the intersection? \$\endgroup\$ – Mag Sep 12 '17 at 11:33
  • \$\begingroup\$ @Mag What do you mean by "math description"? \$\endgroup\$ – Bálint Sep 12 '17 at 12:21
  • \$\begingroup\$ I mean the mathematical expression (equation, inequation or other) of the intersection zone if it's possible. \$\endgroup\$ – Mag Sep 12 '17 at 12:32
  • 1
    \$\begingroup\$ @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. \$\endgroup\$ – Tom 'Blue' Piddock Sep 12 '17 at 12:55
  • 1
    \$\begingroup\$ @Mag - don't tell me in the comments edit your question. \$\endgroup\$ – 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:

enter image description here

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.

| improve this answer | |
  • \$\begingroup\$ Thank you very much @DMGregory That is what i search. I want to know what will change for the hypersphere and hyperball? \$\endgroup\$ – Mag Sep 13 '17 at 20:54
  • \$\begingroup\$ 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. ;) \$\endgroup\$ – DMGregory Sep 13 '17 at 21:24
  • \$\begingroup\$ OK @DMGregory, thank you. Your answer is the better one i found. \$\endgroup\$ – Mag Sep 13 '17 at 21:40
  • \$\begingroup\$ 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? \$\endgroup\$ – Mag Sep 14 '17 at 11:13
  • \$\begingroup\$ 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. \$\endgroup\$ – DMGregory Sep 14 '17 at 11:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.