I'm looking for an algorithm to find the longest chord ("diameter") of a closed polyline. Unfortunately that polyline doesn't have to be convex, but the chord should lie entirely within the curve. Here's an example:
The solution I'm looking for is the dashed red segment.
Can you suggest an efficient algorithm for this? The best we've been able to achieve so far is the N² algorithm that tries all pairs of vertices, but even that seems incorrect since the chord doesn't necessarily pass through two vertices (or does it?).
I'm also interested in the related problem where we are looking for the biggest segment joining two vertices (or the longest part of that segment that lies within the curve if the segment in not fully inscribed). In that case, the N² algorithm works, but is slow for a large number of points.