Skip to content
UniKit

Planar graph untangle

A genuinely playable untangle puzzle: the graph is generated from a circular ring plus a fan triangulation, so a zero-crossing arrangement always exists. Click two points to swap them, and every move recomputes the crossings with a real segment-intersection test until none are left — steps, time and hint count all come from your own actions.

Runs in your browserEvery computation happens in your browser — your data never leaves this device.

Linking board

Click one point to select it, then click another to swap their positions. The round ends when no two segments cross any more (0 crossings).

Crossings 9 · Steps 0 · Time 0.0 s · 2 steps from the circular solution
Crossings
9 / 9
Swaps
0
Steps to the solution
2
Time
0.0 s
Nodes
6
Segments
9
Hints used
0

Keyboard: digit keys select the matching point (two digits in a row swap them), N starts a new game.

The crossing count comes from a real segment-intersection test over every pair: edges sharing an endpoint never count, and the red segments are the ones currently crossing.

What this tool does

  • Swap two points at a time to straighten the crossing segments — the round is done once the crossing count reaches zero.
  • Race a friend on swap count: the same seed and node count always start from the same layout.
  • Build planar-graph intuition: the points sit on an outer ring and the edges form a fan triangulation, so a zero-crossing arrangement always exists — find it.
  • Stuck? Hint really tries every swap and reports the pair that lowers the crossing count the most.

Example

Input

seed demo · 6 points (4x4 grid)

Output

Starting layout: 9 crossings (the red segments are the ones crossing)
Hint: swapping 2 and 6 takes the crossings from 9 down to 2
Then swapping (2,5), (3,5), (5,6) reaches 0 crossings in 3 steps

These numbers come from the real layout for seed demo with 6 points and the real intersection test (segmentsCross / countCrossings), so the same seed reproduces them.

Frequently asked questions

How are crossings counted?

Every pair of segments is tested with the determinant method for a proper intersection; edges that share an endpoint never count, and collinear overlaps are not reported as crossings. The status line and the red segments both come from that test, not from an approximation.

Is the puzzle always solvable?

Yes. The graph is generated by picking points clockwise on the grid border and taking a fan triangulation of that convex polygon, so putting the points back in ring order gives zero crossings. The seeded scramble only makes the start harder - it never makes the puzzle unsolvable.

Why do two clicks swap instead of drag?

Swapping guarantees points never overlap and no point can ever be dropped onto an occupied cell; clicking the same point twice clears the selection and clicking an empty cell explains that only two points can trade places. Neither of those counts as a step.

How does the hint work?

It literally simulates every pairwise swap, keeps the one that lowers the crossing count the most and marks those two points on the board. When no swap lowers the count it says so plainly instead of pretending there is a move.

How are steps and time measured?

Steps only count swaps that really changed the layout (clearing a selection or clicking an empty cell does not count). The timer runs on performance.now() from the first swap until the crossings reach zero, so both numbers come from your own play. Nothing is uploaded.

Can I play with the keyboard?

Yes. Click the board first so keystrokes land there, then digit keys select the matching point (two digits in a row swap them) and N starts a new game.

Keywords:untangleplanar graph

Related tools