📄 709239618866001b157af7095cd7f21d
字号:
package distance;
public class ShortestDistance {
public static int selectPoint1;
public static int selectPoint2;
public static double minDistance;
public static double distance;
/*all of the array start from 0*/
public void findShortestDistance(Point[] PointSet,int start,int end){
if(start < end){
int BreakPoint = (start + end)/2;
findShortestDistance(PointSet, start,BreakPoint);
findShortestDistance(PointSet,BreakPoint + 1,end);
Shortest(PointSet,start,BreakPoint, end);
}
}
public void Shortest(Point[] PointSet,int start,int breakPoint ,int end){
int lengthLeft = breakPoint - start + 1;
int lengthRight = end - breakPoint;
Point[] arrayLeft = new Point[lengthLeft];
Point[] arrayRight = new Point[lengthRight];
for(int i = 0; i < lengthLeft; i++){
arrayLeft[i] = PointSet[start + i];
}
for(int i = 0; i < lengthRight; i++){
arrayRight[i] = PointSet[breakPoint + i + 1];
}
for(int i = start; i < arrayLeft.length; i++){
for(int j = breakPoint + 1; j < arrayRight.length; j++){
double currentDistance = distanceOfTwoPoint(arrayLeft[i],arrayRight[j]);
if(currentDistance < ShortestDistance.distance){
ShortestDistance.distance = currentDistance;
ShortestDistance.selectPoint1 = i;
ShortestDistance.selectPoint2 = j;
}
}
}
}
public double distanceOfTwoPoint(Point pointOne,Point pointTwo){
double x1 = pointOne.getXCoordinate();
double y1 = pointOne.getYCoordinate();
double x2 = pointTwo.getXCoordinate();
double y2 = pointTwo.getYCoordinate();
return Math.sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -