GeometryCollective / geometry-processing-js

A fast, general-purpose framework for geometry processing on the web.
MIT License
496 stars 48 forks source link

How to traverse the boundary loop in counterclockwise order? #3

Closed IsaacGuan closed 6 years ago

IsaacGuan commented 6 years ago

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?

rohan-sawhney commented 6 years ago

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);

2) Define new Face*Iterator classes and replace this line with:

this.current = this.current.prev;
IsaacGuan commented 6 years ago

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!

rohan-sawhney commented 6 years ago

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