Convex Hull
3D Geometry
Computational Geometry
Algorithm
3D Modeling

How to find convex hull in a 3 dimensional space

Data Structures & Algorithms practice on Codemia

Step through 300 algorithm problems with animated visualisers that show the data structure changing as the code runs.

Practice algorithms

Introduction

A 3D convex hull is the smallest convex polyhedron that contains a set of points in three-dimensional space. In theory this is a computational-geometry problem; in practice, most projects should use a proven library and focus on the hull result rather than reimplementing the algorithm from scratch.

What the 3D Hull Represents

You can think of the convex hull as a tight shell wrapped around the outermost points. Any point strictly inside that shell is not part of the hull boundary.

In three dimensions, the hull is typically described by:

  • hull vertices, which are input points on the outer boundary
  • faces, usually triangles in library output
  • adjacency information between edges and faces
  • measurements such as surface area and volume

This is useful in mesh preprocessing, collision detection, robotics, scientific visualization, and bounding-volume generation.

The Practical Algorithmic Picture

Several algorithms can build a 3D hull, including incremental insertion, divide and conquer, and Quickhull. Quickhull is one of the most common practical choices.

The idea is roughly this:

  1. pick extreme points and build an initial tetrahedron
  2. find points outside the current hull
  3. choose a visible face and a farthest outside point
  4. replace visible faces with new faces that include that point
  5. repeat until no outside points remain

That summary is enough to understand the shape of the computation. The hard part is implementing it robustly in the presence of floating-point noise, coplanar points, and face bookkeeping.

Use SciPy in Python

In Python, the practical answer is usually scipy.spatial.ConvexHull, which uses the Qhull library underneath.

python
1import numpy as np
2from scipy.spatial import ConvexHull
3
4points = np.array([
5    [0.0, 0.0, 0.0],
6    [1.0, 0.0, 0.0],
7    [0.0, 1.0, 0.0],
8    [0.0, 0.0, 1.0],
9    [1.0, 1.0, 1.0],
10    [0.2, 0.2, 0.2],
11])
12
13hull = ConvexHull(points)
14
15print("vertex indices:", hull.vertices)
16print("faces:")
17print(hull.simplices)
18print("surface area:", hull.area)
19print("volume:", hull.volume)

Important outputs:

  • 'hull.vertices gives indices of points on the hull'
  • 'hull.simplices gives triangular faces by index'
  • 'hull.area and hull.volume summarize the hull geometry'

The point [0.2, 0.2, 0.2] is inside the outer shell, so it is not a hull vertex.

Visualizing the Hull

If you are debugging geometry, visualization is worth the effort. A simple Matplotlib plot makes it easy to see whether the input points and hull faces match your expectations.

python
1import matplotlib.pyplot as plt
2from mpl_toolkits.mplot3d.art3d import Poly3DCollection
3
4fig = plt.figure()
5ax = fig.add_subplot(111, projection="3d")
6ax.scatter(points[:, 0], points[:, 1], points[:, 2], color="blue")
7
8faces = [points[s] for s in hull.simplices]
9ax.add_collection3d(Poly3DCollection(faces, alpha=0.2, edgecolor="black"))
10
11plt.show()

This is especially helpful when a point you expected to be on the hull is actually inside it.

Degenerate Cases Matter

Not every point set produces a full 3D polyhedron. Some sets are degenerate:

  • all points are identical
  • all points are collinear
  • all points are coplanar

In those cases, a library may raise an error, require special options, or effectively reduce the problem to lower dimension. If your data comes from measurements, it is worth checking whether the point cloud really spans three independent directions before assuming a 3D hull exists.

If You Need C or C++

For lower-level applications, people commonly use Qhull directly or a geometry library such as CGAL. Those libraries are much more robust than most first attempts at a hand-written hull implementation.

Writing the algorithm yourself is reasonable if your goal is educational. Writing it yourself for production is usually a poor trade unless you have a very specialized constraint.

Common Pitfalls

A common mistake is assuming 3D hull construction is only a small extension of the 2D case. The concept is similar, but face management, visibility checks, and numerical stability are much harder.

Another mistake is ignoring nearly coplanar data. Floating-point precision can make apparently simple point sets behave unpredictably if you do not account for tolerance and degeneracy.

A third issue is reimplementing the algorithm when a mature library already exists. Unless you need a research-grade customization, using Qhull through SciPy or another geometry package is usually the right answer.

Summary

  • A 3D convex hull is the smallest convex polyhedron containing all input points
  • Quickhull and related algorithms are common practical solutions
  • In Python, scipy.spatial.ConvexHull is the standard fast path
  • Degenerate and nearly degenerate inputs need special care
  • For production work, use a proven library instead of a hand-rolled geometry engine

Related reading
Course
Intermediate
27 lessons
15 hours
DSA Fundamentals

Master algorithmic patterns and data structures through hands-on LeetCode-style problems - from arrays and hashing to dynamic programming and advanced graphs.

View the course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

Data Structures & Algorithms practice on Codemia

Step through 300 algorithm problems with animated visualisers that show the data structure changing as the code runs.

Practice algorithms

All Rights Reserved.