# 寻找孤立坐标点算法

``````public void sortByDistance(List<Point> points) {
for (int i = 0; i < points.size(); ++i) {
Point a=points.get(i);
double minD=Double.MAX_VALUE;
for (int j = 0; j < points.size(); ++j) {
if (i == j) {
continue;
}
Point b=points.get(j);
double d=calcDistance(a,b);
if(d<minD){
minD=d;
}
}
a.setMinDistance(minD);
}
Collections.sort(points);
}

class Point implements Comparable<Point>{
public Point(double x, double y,String name) {
this.x = x;
this.y = y;
this.name=name;
}
String name;
double x;
double y;
double minDistance;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getX() {
return x;
}
public void setX(double x) {
this.x = x;
}
public double getY() {
return y;
}
public void setY(double y) {
this.y = y;
}
public double getMinDistance() {
return minDistance;
}
public void setMinDistance(double minDistance) {
this.minDistance = minDistance;
}
@Override
public int compareTo(Point o) {
if(o==null){
return -1;
}
return -((Double)this.minDistance).compareTo(minDistance);
}

}
public double calcDistance(Point a,Point b){
double d=Math.sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
return d;
}``````