Shapes & spaces

Minimum vertex guard calculator for a simple polygon

Find a minimum set of polygon vertices that collectively see the whole interior, with exact rational visibility-cell coverage.

Your numbers

One row per point or face; use zero-based indices where requested.

Calculated on your device. Your inputs aren’t sent to us.

Your result

Ready when you are

Enter your inputs and select Calculate.

Report an issue

Behind the numbers

How this calculation works

Find a minimum set of polygon vertices that collectively see the whole interior, with exact rational visibility-cell coverage.

THE FORMULAmin |G| subject to every visibility-arrangement cell being seen by at least one g in G.

A worked example

The U-shaped default needs two vertex guards. The returned guard locations (0,0) and (5,0) cover its two arms and connecting base; the exact arrangement has 44 cells.

Good to know

3–8 simple polygon vertices with integer coordinates within ±1000; no consecutive collinear vertices or holes. Exact rational line arrangement and exhaustive vertex-subset coverage; 3000-cell cap. Returned indices follow counterclockwise order. No unrestricted point-guard or sampled-grid optimality claim.

What the guards must cover

A vertex guard can stand only at a listed corner of the gallery. A location is visible when the complete straight segment to the guard stays inside or on the polygon. Visibility can pass along a boundary, but it cannot jump across an exterior notch. The objective concerns every interior location, not merely the corners.

This restriction matters when interpreting the answer. An unrestricted guard placed in the middle of a room might cover more than any corner. The minimum returned here belongs to the finite vertex-guard problem. It is neither a count of cameras with limited viewing angles nor a guarantee about an actual building with furniture or doors.

Minimum vertex guard calculator for a simple polygon worked exampleMinimum guards = 244 exact visibility cellsCorners (0,0) and (5,0)
Scroll across to see the full diagram.
The U-shaped default needs two vertex guards. The returned guard locations (0,0) and (5,0) cover its two arms and connecting base; the exact arrangement has 44 cells.

Compare this with the Polygon visibility region calculator from interior viewpoint. Choose the fewest polygon vertices whose visibility regions cover the entire polygon, not one visibility region or a common-viewpoint kernel.

Entering an ordered boundary

List the boundary corners in cyclic order, without repeating the first point at the end. Coordinates must be integers within the displayed range. The polygon must be simple: edges may meet at their shared endpoints but cannot cross or touch unrelated edges. Remove a corner lying straight between its immediate neighbors before calculating.

Clockwise boundaries are reversed internally. Consequently, all guard indices refer to the counterclockwise vertex list returned with the result. Guard coordinates provide a second way to identify the chosen locations. Several minimum sets may exist, so a different optimum from a drawing or another program can still have exactly the same guard count.

Why a grid is not a proof

Checking a rectangular grid can miss a narrow unseen wedge behind a reflex corner. Instead, this calculator splits an ear triangulation by every line through a pair of polygon vertices. Those lines include the boundaries where visibility from a candidate vertex can change. Each remaining open cell therefore has one constant set of visible guards.

The cell representative is used to identify that constant set, rather than to approximate arbitrary interior coverage. Exact rational clipping and segment tests avoid floating boundary guesses for the accepted integer input. Covering all open cells also covers the closed boundary by taking closures of the finite collection of closed visibility regions.

Finding the smallest cover

For every cell, the solver records a bit mask of the candidate guards that can see it. Equivalent masks can be combined because they impose the same covering requirement. It then enumerates vertex subsets, retaining the smallest subset that intersects every required visibility mask. The input cap keeps that exhaustive comparison practical in a browser.

The displayed arrangement cells and visibility patterns are useful certificates of what was tested. A failure caused by the cell cap is an unresolved computation, not evidence that no guard set exists. Every valid finite polygon can be guarded from all its vertices; the difficult part is establishing that a smaller chosen set is sufficient.

Working through the U shape

The default boundary traces a five-by-five exterior with a three-unit-wide opening descending into the middle. The left and right arms are separated by that opening. A guard at the lower left sees the left arm and base, while a lower-right guard sees the right arm and base. Their union covers the gallery.

The complete cell-cover search finds two guards and rules out every singleton vertex choice. This is stronger than noticing that two marked guards appear plausible on a sketch. The 44-cell count describes this particular arrangement, not a general formula relating the number of cells to the number of guards.

Reading the certificate

Guard count is the quantity to compare when several solutions are possible. Coordinates identify the returned witness, while the visibility-pattern list shows which groups of vertices can see different regions. The sample-cell list is truncated for readability; the covering calculation still includes every arrangement cell and every distinct pattern.

Exactness here concerns the integer polygon, rational construction and exhaustive finite guard selection. It does not include survey uncertainty in the coordinates or a physically exact line of sight. For a practical camera layout, treat this as an ideal geometric baseline and model height, occlusion, field of view and placement restrictions separately.

Useful changes to investigate

Move a reflex corner and recalculate to see when a previously hidden region becomes visible. Small geometric changes can change the optimum abruptly because a line of sight opens or closes. Increasing room area alone need not require more guards, and adding vertices along an already straight wall would not add genuinely new viewing opportunities.

Compare this page with a visibility-region calculator when the guard location is fixed. That related task answers what one selected point can see. This page asks which permitted locations should be selected together and proves minimality within that candidate set. Preserve the same boundary and index convention when comparing the two outputs.

A few questions, answered

Can guards stand inside the room?

Only original polygon vertices are allowed as guard candidates on this page. Interior point guards define a different optimization problem.

Why not just test a grid?

An arbitrary grid can miss narrow unseen regions. The solver uses exact visibility-constant arrangement cells instead.

Are the guard indices my original row numbers?

They refer to the returned counterclockwise boundary. Clockwise input is reversed, so compare the returned coordinates.

Does a cell-cap error prove guarding is impossible?

No. It means the bounded computation is unresolved; no optimal guard count is claimed.

Find your calculator

Start typing to explore the library.