title: How to write an algorithm to calculate the occlusion percentage of a sphere by another sphere when viewed from a point?
body: <p>Language doesn't matter all that much since this is an algorithm problem, but let's say I'm using Python 3.</p>
  <p>Imagine there are two spheres in a 3D space. The spheres have a center position [x, y, z] and a radius r. I also have a point in the same space, at some known position [x, y, z].</p>
  <pre><code># a simple sample code
  class sphere:
     def __init__(self, pos, r):
        self.pos = pos # a list of 3 floats, [x, y, z]
        self.r = r     # a float
  
  class point:
     def __init__(self, pos):
        self.pos = pos # a list of 3 floats, [x, y, z]
  </code></pre>
  <p>Imagine an observer at the point, with wide enough field of view (this is obviously perspective view, since rays meet at a single point) to see the entirety of both spheres. However, one of the spheres eclipses (occludes) the other.</p>
  <p><a href="https://i.stack.imgur.com/PJoer.png" rel="noreferrer"><img src="https://i.stack.imgur.com/PJoer.png" alt="enter image description here" /></a></p>
  <p>I need to find the ratio of the occluded area on the farther away sphere compared to the entire area that would've been visible without the second sphere which is blocking the view. I need help with figuring out how to write this algorithm.</p>
  <p>Please do not suggest packages that would do this calculation for me out-of-the-box.</p>
  <p><a href="https://i.stack.imgur.com/HQQkr.png" rel="noreferrer"><img src="https://i.stack.imgur.com/HQQkr.png" alt="enter image description here" /></a></p>
  <p>For clarity, I'm after the projected view area on a viewing plane.</p>