How to check if a point is inside an ellipsoid?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
To test whether a point is inside an ellipsoid, you do not need a geometric library. You evaluate a normalized equation and compare the result with 1. If the value is less than 1, the point is inside. If it equals 1, the point lies on the surface. If it is greater than 1, the point is outside.
The simple formula works for axis-aligned ellipsoids. A rotated ellipsoid uses the same idea, but you first transform the point into the ellipsoid's local coordinate system.
Use the Standard Axis-Aligned Formula
An axis-aligned ellipsoid centered at (cx, cy, cz) with semi-axis lengths a, b, and c satisfies:
((x - cx)^2 / a^2) + ((y - cy)^2 / b^2) + ((z - cz)^2 / c^2)
Call that expression value. Then:
- '
value < 1means inside' - '
value == 1means on the surface' - '
value > 1means outside'
Here is a direct Python implementation:
This is the standard computational test and is usually all you need for an ellipsoid aligned with the coordinate axes.
Understand Why the Formula Works
The test is the three-dimensional version of checking whether a point lies inside an ellipse. Each coordinate difference is normalized by the square of the corresponding semi-axis length.
That normalization is the important part. It converts the ellipsoid into a unit sphere test in scaled coordinates. If the combined normalized distance is less than 1, the point is still inside the shape after scaling.
This is also why a sphere is just a special case of the same formula where a, b, and c are equal.
Handle Rotated Ellipsoids by Transforming the Point
If the ellipsoid is rotated, do not change the inclusion test itself. Transform the point into the ellipsoid's local coordinates and then apply the same formula.
The transpose of the rotation matrix reverses the ellipsoid orientation and expresses the point in the ellipsoid's own frame. Once you are in that frame, the ordinary axis-aligned equation applies again.
Be Careful with Floating-Point Comparisons
In real code, exact equality with 1 is often too strict because floating-point arithmetic introduces small rounding errors. A tolerance-based comparison is safer:
This matters most in graphics, physics, and simulation code where a point may lie extremely close to the surface.
Common Pitfalls
The biggest mistake is forgetting to subtract the ellipsoid center before applying the formula. The standard equation assumes the ellipsoid is centered at the origin unless you translate the point first.
Another common issue is using axis lengths instead of semi-axis lengths. The formula expects half-lengths, not full diameters.
It is also easy to ignore rotation. The basic test only works directly when the ellipsoid is aligned with the coordinate axes.
Finally, avoid exact floating-point equality checks for surface classification unless the numbers are symbolic or otherwise exact.
Summary
- For an axis-aligned ellipsoid, compute the normalized quadratic expression and compare it with
1. - Translate the point by the ellipsoid center before testing.
- Use semi-axis lengths
a,b, andc, not full diameters. - For rotated ellipsoids, transform the point into local coordinates first.
- Use a tolerance when deciding whether a point is exactly on the surface.

