geometry
mathematics
ellipsoid
point-inclusion
computational-geometry

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 < 1 means inside'
  • 'value == 1 means on the surface'
  • 'value > 1 means outside'

Here is a direct Python implementation:

python
1def point_in_ellipsoid(point, center, radii):
2    x, y, z = point
3    cx, cy, cz = center
4    a, b, c = radii
5
6    value = (
7        ((x - cx) ** 2) / (a ** 2)
8        + ((y - cy) ** 2) / (b ** 2)
9        + ((z - cz) ** 2) / (c ** 2)
10    )
11
12    if value < 1:
13        return "inside"
14    if value == 1:
15        return "surface"
16    return "outside"
17
18
19print(point_in_ellipsoid((2, 2, 2), (1, 1, 1), (2, 3, 4)))

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.

python
1import numpy as np
2
3
4def rotated_point_in_ellipsoid(point, center, radii, rotation_matrix):
5    point = np.array(point, dtype=float)
6    center = np.array(center, dtype=float)
7    radii = np.array(radii, dtype=float)
8
9    local = rotation_matrix.T @ (point - center)
10    value = np.sum((local / radii) ** 2)
11
12    if value < 1:
13        return "inside"
14    if np.isclose(value, 1.0):
15        return "surface"
16    return "outside"

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:

python
1import math
2
3
4def classify_value(value, tolerance=1e-9):
5    if value < 1 - tolerance:
6        return "inside"
7    if math.isclose(value, 1.0, abs_tol=tolerance):
8        return "surface"
9    return "outside"

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, and c, 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.

Course illustration
Course illustration

All Rights Reserved.