We position a view cone in euclidean 3-space at origin and orient it towards $z$. Through this cone we observe an ellipsoid of arbitrary size, position and orientation which may or may not be intersecting with our cone volume.
Now we wish to find out
- Is this ellipsoid intersecting our view cone volume at all? (i.e. can we see it?)
- If yes, what are the distances of the two planes orthogonal to $z$ that bound not the entire ellipsoid, but only the intersection? (giving us a one-dimensional range along the cone ray that covers the visible part of the ellipsoid)
- Does the visible part of the ellipsoid projected to the far plane cover 100% of the circular intersection of the view cone and the far plane? (i.e. Does it fully occlude any space behind it from the view cone's perspective)
- If yes, what is the nearest distance of a plane at which 100% of that circle is covered? (giving us a depth horizon after which any information further away can be discarded because it is guaranteed to be invisible)
For these questions, I'm not only interested in solutions, but also approaches and general guidance, even if it's just about the 2-space analog case. Are there direct analytical solutions or at least iterative methods that converge quickly, precise or approximate? Would it be easier to use a 4-sided view pyramid rather than a cone?
My background is in linear algebra and implicit surface distance estimation. Projective geometry is very new to me so any pointers are appreciated.
Here's one possible solution that I worked out for the case that we use a Frustum instead of a cone, which also illuminates the use case for my problem a bit. It's untested but I'm fairly certain that it will work.
Ellipsoid Frustum Intersection
The problem is about a form of refining raytracing where we render a big list of convex 3D brushes (and I decided to start with Ellipsoids, since they're so useful) to the screen or a shadow map, without any prebuilt accelleration structure. How does it work? Well, if we had a way to figure out for a portion of the frustum whether it contained a brush, we could
And this brings us to the problem: we want to solve for a tile on screen
You see that the problem is analog to raytracing, but we are frustum tracing: instead of a ray, we extrude and expand a rectangle which forms a 4-sided open-faced pyramid in space, or simpler yet, four planes. The depth values that we are interested in are represented by planes parallel to the screen plane. These planes intersect in each corner of the rectangle to form edge lines. So the participants in this problem are:
Now the screen plane and the wall plane and edge lines are not necessarily arranged symmetrically and orthogonally, but can be skewed due to the position of the screen tile we are interested in. In the beginning, this sounds like an added complication, but it will be helpful that we don't have an invariant here that we might feel must be protected (and instead get another one that we will profit from)
2D Case
Let's drop from 3D space to 2D space and attempt to solve the problem there. Now our ellipsoid is just an ellipse, and our frustum is simply a wedge formed by two lines originating from an eye point (analog to our four planes or four edge lines - here they collapse to the same thing) and a screen line (analog to our screen plane) arranged semi-orthogonally to the eye point.
The first thing we can do to considerably simplify the problem is to non-uniformly scale and rotate our problem space to turn the ellipsoid into a unit circle (analog to the 3D raytracing solution which does the same thing). This will skew our wedge further, but since it was already skewed to begin with, nothing really changed for us. This was the invariant I talked about earlier. Now we're solving the problem for a unit circle, and our wedge still is a wedge, but in ellipse-space. We'll need to save our skew matrix for later so we can transform our solution lines back to world space.
We end up with four possible arrangements of circle and wedge:
A. A circle that crosses both boundary lines - contained, occluding.
B. A circle that crosses only one boundary line - contained, not occluding.
C. A circle that crosses no boundary line and is left of one line and right of the other - contained, not occluding.
D. A circle that crosses no boundary line and is either left or right of both boundary lines - not contained, not occluding.
To resolve these predicates we need seveal analytical equations, which are readily available:
With these two equations we can deduce our near and far lines (which are parallel to the screen line).
After this, we transform the lines back to world space, and that is the 2D case handled.
3D Case
Let's add one more dimension and observe. Analog to the 2D case, we can rotate and scale the ellipsoid into a unit sphere. Our wall planes, edge lines and screen plane will be transformed to ellipsoid-space, and we will simply transform our solution back later on.
These are our possible cases in 3-space:
A. A sphere that intersects all wall edges - contained, occluding.
B. A sphere that intersects one or more wall planes and is inside the frustum - contained, not occluding.
C. A sphere that intersects no wall planes and is inside the frustum - contained, not occluding.
D. A sphere that intersects no wall planes and is outside the frustum - not contained, not occluding.
These are the analytical equations we need to solve all predicates, and again, this is all standard stuff:
With these equations we can deduce our near and far planes (which are parallel to the screen plane).
After this, we transform the planes back to world space, and are all done.
Limitations and Caveats
The solution won't work for ellipsoids with a zero (disc) or infinite component (cylinder of infinite length) because we can't transform those back to unit spheres (discs will cause frustum walls to become parallel, cylinders will cause them to collapse to a single plane). I guess one could design more robust tests for those cases, or attempt a solution for quadrics in general.
I also didn't cover any tests for ellipsoids behind the screen plane at eye coordinate or for the case when the eye coordinate is inside the ellipsoid. Those need to be handled as well.
Optimization
Once the algorithm is written down, there are a lot of opportunities to zero or fold duplicate/unused element computations, so I'm fairly certain that it can be crunched down to a small solution that is completely incomprehensible without this document. What I like about this solution is that we get a perfect analytical result without any iterations, and that should translate to potentially hundred thousands if not millions of ellipsoid brushes per frame.
Generalization
This technique is also valid for orthogonal projection without any changes.
Nothing speaks against following this approach with convex non-uniformly scaled primitives other than ellipsoids, as long as ray and plane intersection/bounding tests are available for the primitive or a slice of it. Spheres are particularly convenient because they are invariant to rotation and their slices are always circles. Cubes produce triangular, quadliteral and hexagonal slices. Tetrahedra produce triangular and quadliteral slices. Cylinders and cones produce circles and capped hyperbolic slices.
It nevertheless helps to know that slices of a convex primitive are also always convex.
Could this be done with signed distance estimators? Since our primitive is convex, we can use faster newton-raphson to converge a ray to the surface, in my experience that's under 7 iterations on average. But one has to come up with new plane bounding estimators that also work with 2D slices of a 3D field, which is just a big question mark to me. On the upside, this technique would also work with non-uniformly scaled distance fields.