
A new algorithm for finding a visual center of a polygon - lobo_tuerto
https://www.mapbox.com/blog/polygon-center/
======
opticalflow
While 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.

~~~
chrisseaton
Thanks 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
I 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
That sounds fascinating, can you explain the project a bit more?

~~~
opticalflow
We were doing GPU-based 2D-3D conversion for HD and 4K and one of the
intermediate steps required that we compute a DT (distance transform), and JFA
was perfect for this. The DT was used along with a Hough transform (also real-
time) to conduct vanishing point and geometry analysis.

------
coreyp_1
Beautiful! 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
By 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
There 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.

~~~
vanderZwan
The 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
Good to know! I must've been lucky, since most tSNE plots I've worked with
were pretty tame in that respect.

------
landtuna
What'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.

~~~
Houshalter
That 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.

~~~
iak8god
> That would give you the thickest part of the shape, not necessarily the
> center.

But we're looking for the "visual center," defined in the article as "a point
inside a polygon with as much space as possible around it."

~~~
Houshalter
Right, but I think that definition falls apart if you look at pathological
shapes instead of nice convex ones. If you just randomly generate polygons,
the thickest part of the shape can appear anywhere, including a very far off
edge. And if you cut a tiny opening into that part of the shape, the center
would completely move.

------
crazygringo
But 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.

~~~
chrisseaton
> 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
The 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.

------
Boothroid
Interesting - 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.

------
kitanata
Clever. I love to see when complex problems can be easily approximated using
existing algorithms and techniques. Very cool!

