is there any convenient API in JTS that would help to
- find two most distant points in line
- find two most distant points in polygon
I think all of the JTS methods relating to distance are looking for the nearest or shortest. But providing you don't have too many vertices then you could do a brute force O(N*N) search:
GeometryFactory gf = new GeometryFactory();
double maxDist = 0;
Point start = null, end = null;
for (Coordinate c : geom.getCoordinates()) {
Point p = gf.createPoint(c);
for (Coordinate c2 : geom.getCoordinates()) {
Point p2 = gf.createPoint(c2);
double d = DistanceOp.distance(p, p2);
if (d > maxDist) {
maxDist = d;
start = p;
end = p2;
}
}
}
And if you need to consider points along the lines then add
geom = Densifier.densify(geom, .01);
before you start, though obviously this pushes N up.