javascript - How do I clip a line segment between two known y values? -
i implementing algorithm find optimal label location polygon. can found here.
the gist must sort polygon's vertices y
values. then, each y
"draw" horizontal line @ point. divides polygon strips , ends looking this:
once these strips created, must find midpoints of segments contained in each one. stuck. example, in strip #2, leftmost segment has no endpoints define in strip's scope. endpoints @ top of strip #1 , bottom of strip #3.
how clip longer line segment segment contained entirely in upper , lower bounds of strip #2?
more specifically, how determine 2 endpoints (top of strip 1, bottom of strip 3) endpoints line intersecting strip #2 on left side?
the classical approach keep "active list" stores indexes of edges straddling current ordinate. when go ordinate next, edges can enter or leave list (they once only). keep updated.
the list empty, ends empty , should contain number of edges @ times.
if polygon edges never cross, can keep list ordered left right.
Comments
Post a Comment