7 ms·
A new algorithm for finding a visual center of a polygon
- coreyp_1 9y agoBeautiful! I would love to see an animation of it in action (a la https://bost.ocks.org/mike/algorithms/ https://bost.ocks.org/mike/algorithms/)!
- vanderZwan 9y agoBy pure coincidence, I just had a discussion at work the other day on how to automatically place labels for clusters on tSNE plots. It looks like all I need is a sensible way to convert the points to a polygon first (convex hull won't work here, for obvious reason)
- hobofan 9y agoThere are ways to get the most "typical" (I think there is a better term for that) sample of a cluster, which should usually lie in the center of the cluster. AFAIK that's the traditional way to achieve what you are trying to do.
- alexcnwy 9y agoTry compute the median point across all members of the cluster then compute the cosine similarity between each point in the cluster and the median of that cluster and use the most similar as your label point.
- vanderZwan 9y agoThe clusters on our tSNE plots tend to be stretched out, have concave bits and en up intertwined - we'd have the exact same problem outlined in this article. In fact, that was the whole reason we started discussing it, since I initially proposed just doing what you suggested
- hobofan 9y agoGood to know! I must've been lucky, since most tSNE plots I've worked with were pretty tame in that respect.
- blt 9y agoLook up Alpha Shapes.
- vanderZwan 9y agoThank you! I knew it was a matter of finding the right keywords to search for. Time to experiment a bit. EDIT: Oh, wait: > Basic alpha shapes are based on the Delaunay triangulation. At that point we might as well go for DT based approaches, don't we?
- landtuna 9y agoWhat's wrong with "the lawnmower approach"? Imagine you're mowing the lawn in a spiral from the outside in. When a section is completely mowed, just continue spiraling in the remaining area. The center is the last place with high grass. The only drawback I see is that you could get multiple answers for certain shapes. But for the ones in the post, I think the answer is about the same.
- deleted 9y ago[deleted]
- ricardobeat 9y agoIm not sure about the exact cost, but at first sight this approach would still require a lot more operations per line - you need to keep the lawnmower inside by measuring distance/intersection to closest edge, plus track the already mowed area. Maybe making the lawnmower wide enough could make it fast and accurate enough for specific use cases.
- theoh 9y agoThat's equivalent to calculating the "straight skeleton", which is mentioned in the article as being among the published solutions, but too slow and error-prone. https://en.wikipedia.org/wiki/Straight_skeleton https://en.wikipedia.org/wiki/Straight_skeleton There's no explicitly spiraling/lawnmower aspect to the straight skeleton: you may have a raster-based incremental literally spiralling solution in mind, but for the geometric examples they show this would probably be inefficient. It's going to have to traverse a large multiple of the perimeter of the polygon as it spirals.
- Houshalter 9y agoThat would give you the thickest part of the shape, not necessarily the center. If I'm understanding correctly anyway. E.g. imagine a long skinny shape with a big thick circle at the end. The lawnmower would finish shaving the main part of the shape and declare the circle the center! If I had to design an algorithm to do this, my idea would be to sample a bunch of points on the polygon, then take their median x and y values. Then find the closest spot on the polygon to that value, if it's not inside the polygon.
- kitanata 9y agoClever. I love to see when complex problems can be easily approximated using existing algorithms and techniques. Very cool!
- opticalflow 9y agoWhile their approach is clever, it is not guaranteed to converge in a fixed number of iterations. Author states that constrained Delaunay Triangulation is "slow and error-prone". I disagree -- I've implemented parallel and recursive Delaunay on GPU before, and it converges in a fixed number of recursions -- for a taste of the general approach, see here: http://www.comp.nus.edu.sg/~tants/jfa/i3d06-submitted.pdf http://www.comp.nus.edu.sg/~tants/jfa/i3d06-submitted.pdf JFA could certainly be "abused" for this purpose.
- vanderZwan 9y agoFor those who don't immediately know what JFA stands for: http://www.comp.nus.edu.sg/~tants/jfa.html http://www.comp.nus.edu.sg/~tants/jfa.html
- chrisseaton 9y agoThanks for posting this. I was convinced that Delaunay triangulation was a good example of irregular parallelism - something that fundamentally doesn't work well on a GPU, and have been telling people this for years, so I'll look forward to reading the paper. (A Voronoi diagram is just a different way to show a Delaunay triangulation isn't it?)
- opticalflow 9y agoI was running this on (high end) GPUs back in 2011, in real-time (30fps), on 1920x1080 video textures. I can confirm that the clever recursion and performance of this is mind-boggling. Oh, and you get a distance transform out of it as an intermediate step, just for giggles. My general take is that while linear kernel-thinking in parallel might get nowhere, this is a prime example of recursion solving the problem when parallelism is available. I wish I could claim to have invented it... :)
- malux85 9y agoThat sounds fascinating, can you explain the project a bit more?
- crazygringo 9y agoBut does the "pole of inaccessibility" actually work? Imagine a long rectangle. The pole of inaccessibility will be a range along most of the length of the rectangle... it won't find the center at all! Even the illustrated "coastline" example is horizontally centered only by chance, because that happens to be the thickest part. So not clear at all this finds a plausible "visual center" by any means.
- Mizza 9y agoIf you read the article, you'll see that one of their optimizations is to start with the centroid of the polygon, sort, and then discard ties, so it should still get the correct answer for your described shape.
- chrisseaton 9y ago> The pole of inaccessibility will be a range along most of the length of the rectangle How could it be a range like that? Surely some points on the range would be closer to the short edges than others, making them more accessible?
- eridius 9y agoThe range is a line parallel to the long edges that runs down the center of the rectangle. It ends when it gets closer to the short edges than it is to the long edges.
- deleted 9y ago[deleted]
- Boothroid 9y agoInteresting - but how does the author know this isn't already present in proprietary software, but hidden? I get a little nervous about claims to novelty when e.g. Esri has decades of research behind its labelling algorithms.