DevTools Logo

Convex Hull Algorithm Visualizer

Convex Hull Algorithm Visualizer

Compare Graham scan and Jarvis march step by step, entirely in your browser

Runs in your browser
Try an example

Point set

7 points · 7 lines · 58 chars

Step playback

Hull: 4 of 7 points · area 121900
Policy: points that lie on a hull edge but are not corners are excluded. The hull is listed counter-clockwise with y pointing up; on screen (y down) it appears clockwise.

Step 1 of 17: Start at the lowest pivot

Hull vertices: (70, 70) → (520, 75) → (550, 330) → (90, 350)

About

Explore accepted and rejected turns, stack state, collinear edge handling, and hull highlighting for two classic computational geometry algorithms. Everything runs client-side.

Examples

Square with an interior point

Input
grahamScan([{0,0}, {4,0}, {4,4}, {0,4}, {2,2}, {1,0}])
Output
hull 4 corners; {1,0} rejected as collinear interior

Edge-collinear points pop off the stack so only true corners survive.

All-collinear degeneracy

Input
grahamScan([{0,0}, {1,1}, {2,2}, {3,3}])
Output
hull [{0,0}, {3,3}] with collinear rejections

With no area, the hull collapses to the two extreme endpoints.

About this tool

Convex Hull Visualizer computes bounding polygons with grahamScan(points), jarvisMarch(points), and convexHull(points, algorithm = 'graham'): each returns a counter-clockwise hull plus a steps log (consider/accept/reject/wrap/complete with reasons and stack snapshots). At least 3 distinct points are required, duplicates are removed, and collinear edge interiors are dropped in favor of farther endpoints.

Graham scan sorts by polar angle around the lowest pivot and pops right turns or collinear interiors; Jarvis march gift-wraps from the leftmost point, preferring the most counter-clockwise (then farther) candidate. Both report deterministic, repeatable step sequences for the same input.

generateRandomPoints(seed, count = 20, width = 600, height = 400) emits browser-safe seeded points via an LCG (1664525/1013904223): the same seed and dimensions always match, different seeds diverge.

How to use this tool

  1. Supply 3+ distinct points

    Provide at least three unique coordinates — fewer throws an explicit 3-distinct-points error.

  2. Run Graham, Jarvis, or both

    Pick the algorithm (or compare both) and read the hull vertex list counter-clockwise.

  3. Step through decisions

    Walk the steps: consider/accept shows the frontier, reject names right turns versus collinear interiors.

  4. Seed random sets for demos

    Use generateRandomPoints with a fixed seed for a reproducible classroom point cloud.

Use cases

Teaching scan vs march

Contrast polar-angle sorting against gift-wrapping on the same set — same vertex set, different decisions.

Explaining collinear handling

Show why nearer edge points are rejected and only farther endpoints are kept.

Generating deterministic demos

Seed a point cloud once and replay the identical hull animation every run.

Common mistakes

Mistake:Expecting collinear edge points to survive.

Fix:Collinear interiors are intentionally popped (cross <= 0) — only the farthest endpoint on each edge stays.

Mistake:Passing fewer than 3 distinct points.

Fix:Duplicates are collapsed first, so three entries with only two unique locations still throws — add a genuinely distinct point.

Mistake:Assuming hull order is input order.

Fix:Output is counter-clockwise from the pivot/leftmost start, not the order you supplied.

Frequently asked questions

What does this tool do?

It computes counter-clockwise hulls with grahamScan, jarvisMarch, and convexHull(points, algorithm), each returning hull plus a consider/accept/reject/wrap/complete steps log — plus seeded generateRandomPoints(seed, count, width, height) clouds that reproduce exactly.

What happens with collinear or duplicate points?

Duplicates are removed first and you need 3 distinct points or it throws; collinear edge interiors are rejected (cross <= 0) so only farther endpoints survive — an all-collinear set collapses to its two extremes.

Is my point data uploaded or stored?

No. Sorting, wrapping, and seeded generation run entirely in your browser.

Do Graham scan and Jarvis march agree?

Yes on the vertex set — same counter-clockwise hull, reached by different decisions (polar-angle pops versus gift-wrapping comparisons), which the step logs make visible.

References & standards