Convex Hull Using Brute Force Method | Easy Explanation, Pseudocode & Python

EmailTwitterLinkedInFacebookWhatsAppShare

1. Idea in simple words

Imagine many nails hammered into a board.
Now stretch a rubber band around all of them.

The shape made by the rubber band is called the convex hull.

The slow brute force method tries to find which point pairs form the outer boundary.

Main thought

Take every pair of points and ask:

“Does the line joining these two points leave all other points on only one side?”

  • If yes, that edge belongs to the convex hull.
  • If no, that edge is inside, so ignore it.

That is why this method is called slow:
it checks all pairs, and for each pair it checks all other points.


2. Visual intuition

Suppose you pick two points A and B.

Draw a line from A to B.

Now check every other point:

  • if all points are on the left side, or
  • all points are on the right side,

then AB is an outer edge.

But if some points are on one side and some on the other side, then that line cuts through the set, so it is not a hull edge.


3. Tiny example

Points:

A(1,1), B(2,4), C(4,5), D(6,3), E(5,1), F(3,2)

If you test edge A-E, maybe all other points lie above it.
So A-E is a hull edge.

If you test edge B-D, some points may lie above and some below.
So B-D is not a hull edge.


4. Orientation test

To know which side a point lies on, we use this value:

[(B_x – A_x)(P_y – A_y) – (B_y – A_y)(P_x – A_x)]

For points A, B, P:

  • positiveP is on one side
  • negativeP is on the other side
  • zeroP is on the same line

This is the key math behind the algorithm.


5. Brute force algorithm

For every pair of points (Pi, Pj):

  1. Assume it might be a hull edge.
  2. Check every other point Pk.
  3. Compute orientation of (Pi, Pj, Pk).
  4. If points appear on both sides, reject the edge.
  5. If all points stay on one side (or on the line), accept the edge.

6. Pseudocode

BRUTE_FORCE_CONVEX_HULL(points):
hull_edges = empty list
for each pair of points (Pi, Pj):
pos = 0
neg = 0
for each other point Pk:
value = orientation(Pi, Pj, Pk)
if value > 0:
pos = pos + 1
else if value < 0:
neg = neg + 1
if pos == 0 or neg == 0:
add edge (Pi, Pj) to hull_edges
return hull_edges

7. Time complexity

There are:

  • about n² pairs
  • and for each pair, we check n points

So total time is:

[O(n^3)]

That is why it is called slow.


8. Python implementation

This version finds the hull edges and also arranges hull points in circular order.


This animation shows hull edges being added one by one.


9. One-line summary for your tutorial

The brute force convex hull method checks every pair of points and keeps only those pairs for which all remaining points lie on one side of the line.


10. Best short narration script

You can say this in your tutorial:

“In the slow convex hull method, we try every possible pair of points. For each pair, we check all other points. If all points lie on only one side of that line, then that pair forms an outer boundary edge. Repeating this for all pairs gives the convex hull. It is simple to understand, but slow, because it takes O(n³) time.”


I hope this tutorial will create a good foundation for you. If you want tutorials on another topic or you have any queries, please send an mail at contact@spatial-dev.guru.

Leave a ReplyCancel reply

Discover more from Spatial Dev Guru

Subscribe now to keep reading and get access to the full archive.

Continue reading

Discover more from Spatial Dev Guru

Subscribe now to keep reading and get access to the full archive.

Continue reading