⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 709239618866001b157af7095cd7f21d

📁 在eclipse下开发的求平面上两点之间的最短距离。通过随机在平面上生成无数个点
💻
字号:
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 + -