Here's a thought on how to get it to O (n 2 log n). I don't know anything about computational geometry, so I will mark this community wiki; Please feel free to improve this.
Pre-process the convex hull by finding for each point the range of slope of the lines through this point, so that the set lies completely on one side of the line. Then invert this relation: build a spacing tree for slopes with points in the leaf nodes, so when prompted with a slope, you will find points such that there is a tangent through these points.
If there are no sets of three or more collinear points on the convex hull, for each slope (two on each side) there should be no more than four points, but in the case of collinear points we can simply ignore the intermediate points.
Now iterate over all pairs of points (P, Q) on the convex hull. We want to find the point R so that the triangle PQR has a maximum area. Taking PQ as the base of the triangle, we want to maximize the height by finding R as far as possible from the PQ line. The line through R parallel to PQ must be such that all points lie on one side of the line, so we can find a limited number of candidates in O (log n) time using a tree with a pre-built interval.
To improve this in practice, branch and snap in a set of pairs of points: find the upper boundary of the height of any triangle (for example, the maximum distance between two points) and discard any pair of points that is multiplied by this upper boundary less than the largest triangle found.
Jouni K. Seppänen
source share