PistonDevelopers / graphics

A library for 2D graphics, written in Rust, that works with multiple back-ends
MIT License
478 stars 55 forks source link

Bidirectional triangulation algorithm - tail tip case #156

Closed bvssvni closed 10 years ago

bvssvni commented 10 years ago

It is impossible to have general polygon triangulated correctly under streaming. This is because once you send a triangle to the GPU you don't know whether another edge will intersects it later in the stream.

There is a condition where you have a concave polygon but still guarantee that no later triangle will intersect. I call this the "tail tip case": Imagine the tip of a tail or rope where the shape has concave attributes on one side, because the tail is bent.

If we start at the tip and stream points in both directions, we could compute a skewness factor or the candidate triangles we would have by selecting either next point. We pick the triangle with least skewness and use the line between the last picked points in both directions as the base line for the next triangle. Keep doing this until we get the same point from both directions.

bvssvni commented 10 years ago

The procedural algorithm that generates the points needs to be able to traverse in two directions (think double-linked list). This class of algorithms includes any algorithm that can randomly access points (think arrays).

bvssvni commented 10 years ago

The bidirectional streaming algorithm requires two closures instead of one.

bvssvni commented 10 years ago

This algorithm would support spirals.

bvssvni commented 10 years ago

Suggestion: Find the smallest angle in each triangle and pick the triangle with the largest smallest angle.

bvssvni commented 10 years ago

One weakness with the algorithm is that you need to start at the tip, or else it will not work.

bvssvni commented 10 years ago

This is an issue for Rust-Graphics-Lab.

Closing for now.