<p>Assuming that all blue half edges have their <em>twin, next and prev</em> correctly set
and
assuming that all blue half edges have their purple <em>twin</em> assigned.</p>
<p>Then assigning the <em>next</em> to the red half edge boils down to:</p>
<pre><code>runner = red
while(runner-&gt;twin-&gt;prev) 
   runner = runner-&gt;twin-&gt;prev

runner-&gt;twin-&gt;prev = red
(red-&gt;next = runner-&gt;twin)
</code></pre>
<p>While building the mesh keep a list of all half edges which do not have a <em>twin</em>. Then when finished processing all faces create a new half edges for all half edges which have no twin (these are the purple edges). Then afterwards run this procedure.</p>

CC BY-SA 4.0
2023-09-08T00:46:55.263Z
This is pretty genius thanks!
ThisAccountIsForGameDev
CC BY-SA 4.0
2023-09-07T07:51:16.507Z
2023-09-07T07:51:16.507Z
Reynolds
<p>I was reading <a href="https://computergraphics.stackexchange.com/questions/9566/how-to-handle-half-edge-boundary-edge-iteration-from-vertex">this question</a> regarding half edges from 3 years ago and the selected answer seemed pretty smart to me. However, while actually implementing it I'm confused at the part where I have to fill in the next pointer of an opposite half-edge of a half-edge.</p>
<blockquote>
<p>So the boundary edge actually does have an opposite (or pair pointer) and that opposite is fully integrated into the pointer structure, complete with next pointer and everything. Just that its face pointer in null, thus denoting an empty face or hole. So basically every hole is represented by a null face with half edges going around it.</p>
</blockquote>
<p><a href="https://i.sstatic.net/SOKur.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/SOKur.png" alt="enter image description here" /></a>
So say that the half edges of a face are winded counter-clockwise (blue arrows). For the red half edge, the 'next' pointer of the edge should be the next purple half edge... But how do I obtain the purple half edge from the red half edge? For this case, I can get it from the red half edge by the sequence of the following operations: opposite - previous - opposite - next - next - opposite, but is this the best approach and is it scalable? I would appreciate it if someone could guide me to a smarter method.</p>

<c++><computational-geometry><algorithm><geometry><half-edge>
What is a smart way to fill in the 'next' pointer of a opposite half-edge of a boundary?
ThisAccountIsForGameDev
# What is a smart way to fill in the 'next' pointer of a opposite half-edge of a boundary?

(Asked by: username_0 on 2023-09-06)

I was reading [this question](https://computergraphics.stackexchange.com/questions/9566/how-to-handle-half-edge-boundary-edge-iteration-from-vertex) regarding half edges from 3 years ago and the selected answer seemed pretty smart to me. However, while actually implementing it I'm confused at the part where I have to fill in the next pointer of an opposite half-edge of a half-edge.

> So the boundary edge actually does have an opposite (or pair pointer) and that opposite is fully integrated into the pointer structure, complete with next pointer and everything. Just that its face pointer in null, thus denoting an empty face or hole. So basically every hole is represented by a null face with half edges going around it.

[![enter image description here](https://i.sstatic.net/SOKur.png)](https://i.sstatic.net/SOKur.png)
So say that the half edges of a face are winded counter-clockwise (blue arrows). For the red half edge, the 'next' pointer of the edge should be the next purple half edge... But how do I obtain the purple half edge from the red half edge? For this case, I can get it from the red half edge by the sequence of the following operations: opposite - previous - opposite - next - next - opposite, but is this the best approach and is it scalable? I would appreciate it if someone could guide me to a smarter method.

**Tags:** c++, computational-geometry, algorithm, geometry, half-edge


---

## 1 answers

### Answer by username_1 on 2023-09-07. Score: 0 | Accepted answer

Assuming that all blue half edges have their *twin, next and prev* correctly set
and
assuming that all blue half edges have their purple *twin* assigned.

Then assigning the *next* to the red half edge boils down to:

```
runner = red
while(runner->twin->prev) 
   runner = runner->twin->prev

runner->twin->prev = red
(red->next = runner->twin)

```

While building the mesh keep a list of all half edges which do not have a *twin*. Then when finished processing all faces create a new half edges for all half edges which have no twin (these are the purple edges). Then afterwards run this procedure.

> **Comments:**
> **username_0**: This is pretty genius thanks!  

---

