half edge structure
edge removal
computational geometry
data structures
geometry processing

How to remove an edge from a half edge structure?

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Introduction

Removing an edge from a half-edge structure is not just a delete operation. It changes topology, so the real task is to relink neighboring half-edges, update face and vertex references, and decide exactly what "remove" means in your mesh editing model.

First decide what removal means

In a half-edge mesh, "remove an edge" can mean several different things:

  • delete an interior edge and merge two adjacent faces
  • collapse an edge and merge its two vertices
  • remove a boundary edge from an open mesh

Those are different operations. The simplest case to explain is removing an interior edge that separates two faces and merging those faces into one.

The half-edge objects involved

For one edge, you usually have two half-edges:

  • 'he'
  • 'he.twin'

Each half-edge also has:

  • 'next'
  • 'prev'
  • 'vertex'
  • 'face'

Removing the edge means bypassing both half-edges in their face loops and then fixing any face or vertex references that still point to them.

A merge-faces style removal

Here is pseudocode for the topological part of removing an interior edge:

python
1def remove_interior_edge(he):
2    twin = he.twin
3
4    if he.face is None or twin.face is None:
5        raise ValueError("expected an interior edge")
6
7    if he.face is twin.face:
8        raise ValueError("edge does not separate two different faces")
9
10    # Bypass he in its face loop
11    he.prev.next = twin.next
12    twin.next.prev = he.prev
13
14    # Bypass twin in the opposite face loop
15    twin.prev.next = he.next
16    he.next.prev = twin.prev

That reconnects the surrounding cycle so the two half-edges are no longer part of the boundary traversal.

Updating face references

Once the loops are reconnected, you usually keep one face and discard the other. Every half-edge that used to belong to the discarded face must now point to the surviving face:

python
1def reassign_face(start_he, new_face):
2    current = start_he
3    while True:
4        current.face = new_face
5        current = current.next
6        if current is start_he:
7            break

Then call:

python
reassign_face(twin.next, he.face)

If either face object stored a representative half-edge that is about to be deleted, update that pointer too.

Updating vertex references

Vertices often store one outgoing half-edge as an entry point into local traversal. If a vertex points at he or twin, redirect it to another valid outgoing half-edge nearby.

This step is easy to forget, but it matters. Without it, the mesh may still look fine until later code asks a vertex for one of its incident half-edges and receives a deleted reference.

Validity checks matter

Not every edge should be removed blindly. Before removing one, check conditions such as:

  • the edge is not on the boundary if your code assumes two faces
  • removing it will not create a non-manifold configuration
  • the surrounding faces are compatible with your mesh rules

Topology code fails less often in the removal step itself than in the assumptions made before it.

Common Pitfalls

  • Treating edge removal like a simple delete instead of a topological update.
  • Forgetting that he and he.twin must both be removed consistently.
  • Updating next and prev pointers but forgetting face or vertex representative references.
  • Applying an interior-edge algorithm to a boundary edge or non-manifold case.

Summary

  • In a half-edge mesh, removing an edge means relinking topology, not just deleting two objects.
  • You must decide whether the operation is edge deletion, face merge, or edge collapse.
  • For an interior face-merge removal, bypass both half-edges and reassign the surviving face references.
  • Always update vertex and face representatives so later traversals remain valid.

Course illustration
Course illustration

All Rights Reserved.