Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Self intersecting polygon -- some sub regions not getting detected #17

Open
dan-reznik opened this issue Sep 6, 2020 · 6 comments
Open

Comments

@dan-reznik
Copy link

dan-reznik commented Sep 6, 2020

Dear Manuel, I am really excited about integrating simplepolygon into a locus-drawing js browser app I've been developing over the past few months. It draws loci of centers of families of triangles "mounted" on ellipses.

Browserifying simplepolygon worked like a charm.

However I am having a few issues with the results returned by simplepolygon. Consider first of all one 800-long sample polygon (it's actually a curve approximation), you can see it live here: https://bit.ly/2Zg7Mv1

x14 raw

As you can see, the above curve has 6 self intersections and 7 simple subregions. The coloring scheme below reveals the independent subregions returned by simplepolygon. unfortunately, only 3 are returned. Any idea why?

x14 filled

For your own testing I am attaching a zipped json w the 800 vertices:

vtx-X14.zip

@mclaeysb
Copy link
Owner

mclaeysb commented Sep 7, 2020

Hi there. Interesting question.

I'll try to take a look at this in the coming days!

@dan-reznik
Copy link
Author

not sure if you had a chance to look at this bug yet, but we would truly appreciate if you could fix it. here is a simpler polygon, shaped as the infinity symbol, clearly with two separate simply-connected regions,
single_region_problem
where the algo returns a single region . a json with the vertices is attached.
locus_json_13092020_103525.zip

@mclaeysb
Copy link
Owner

Thanks! Will look at this on friday!

@dan-reznik
Copy link
Author

looking fwd to it. it is being used heavily on our app https://dan-reznik.github.io/ellipse-mounted-loci-p5js/

@mclaeysb
Copy link
Owner

Hi Dan

Super cool and crazy app you're building there!

I've tested simplepolygon on the last example you've posted. After including the vertex list in a geojson feature and running the algorithm, I got the error message

Error: The input polygon may not have duplicate vertices (except for the first and last vertex of each ring)

Indeed, [0, 0] is included twice in the input polygon.

If I tweak the input polygon a bit and remove both [0, 0] points, it runs, but returns only one connected shape (which is obviously wrong).

Screen Shot 2020-09-26 at 19 09 28

I don't remember if this uniqueness limitation comes from the original paper or not (it doesn't seem to be accessible anymore). In any case, I don't have the time or resources now to go and fix this problem - we're diving in some high-end math here, and this was a spare-time project from a couple of years ago.

It looks like you app has a lot of very symmetrical structures, so this problem will indeed often occur. So all I can do for now is to redirect you to some more robust geometric libraries such as JSTS which are better at handling degeneracies like this. I don't think this library has an equivalent algorithm, but it might have some other helpful tools that might help you to move on.

All the best with the app!
Manuel

@dan-reznik
Copy link
Author

dan-reznik commented Sep 26, 2020 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants