GeometryCollective / geometry-processing-js

A fast, general-purpose framework for geometry processing on the web.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to traverse the boundary loop in counterclockwise order?

IsaacGuan opened this issue · comments

For traversing all the vertices on the boundary, I can use Mesh.boundaries to find out all the boundary loops contained in this mesh which are represented by "imaginary" faces, and then use Face.adjacentVertices() or Face.adjacentHalfedges() to iterate over the the vertices/halfedges of a boundary loop. But I find that the sequence of the items in these iterators is not in CCW order. How can I traverse the boundary loop in counterclockwise order?

The current iterators traverse interior elements in CCW order and boundary elements in CW order. You could do one of two things:

  1. Manually traverse the boundary as follows:
let he = face.halfedge; // face is "imaginary"
do {
    let v = he.vertex;
    // do something with v

    he = he.prev;
} while (he !== face.halfedge);

  1. Define new Face*Iterator classes and replace this line with:
this.current = this.current.prev;

Thank you for the quick reply! Now I find I asked a really dump question.
I am implementing tutte embedding using this library, so I just fixed the boundary vertices in clockwise order instead of counterclockwise, and it is getting good result.
Thank you very much!

I added a flag to use the iterators in CCW or CW order.