-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathGreatestDistance.java
More file actions
34 lines (28 loc) · 852 Bytes
/
GreatestDistance.java
File metadata and controls
34 lines (28 loc) · 852 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package own;
/**
* Finds the maximum distance between n set of points. Worst case is O(n^2) when
* the polygon determined by the set of points is convex. Can be reduced to
* O(nlogn).
*/
public class GreatestDistance {
Point[] points;
public GreatestDistance(Point[] points) {
this.points = points;
}
public double getMaximumDistance() {
ConvexHull hull = new ConvexHull(points);
Point[] hull_points = hull.getConvexHull();
double max_distance = 0;
// TODO (mihaelacr) this can be reduce to O(n)
for (int i = 0; i < hull_points.length; i++)
for (int j = i + 1; j < hull_points.length; j++) {
Point p1 = points[i];
Point p2 = points[j];
double current_distance = p1.getEuclideanDistance(p2);
if (current_distance > max_distance) {
max_distance = current_distance;
}
}
return max_distance;
}
}