地图两点间坐标的生成

     /**
	 * 两点间坐标的生成
	 * @param x1
	 * @param y1
	 * @param x2
	 * @param y2
	 */
	public static void cal(BigDecimal x1, BigDecimal y1, BigDecimal x2, BigDecimal y2){
		//坐标的标准增量
		BigDecimal _100 = new BigDecimal(0.000100);
		//坐标的推算方法(加或减)
		boolean xAddTrue = true;
		boolean yAddTrue = true;
		if(x1.compareTo(x2) > 0){
			xAddTrue = false;
		}
		if(y1.compareTo(y2) > 0){
			yAddTrue = false;
		}
		//经度增量的绝对值
		BigDecimal xAbs = x1.subtract(x2).abs().setScale(6, BigDecimal.ROUND_HALF_UP);
		//维度增量的绝对值
		BigDecimal yAbs = y1.subtract(y2).abs().setScale(6, BigDecimal.ROUND_HALF_UP);	
		BigDecimal abs = ((xAbs.compareTo(yAbs) > 0)?xAbs:yAbs).setScale(6, BigDecimal.ROUND_HALF_UP);
		//标准增量下的循环次数
		BigDecimal degree = abs.divide(_100, 0, BigDecimal.ROUND_DOWN);  
		//经度实际增量
		BigDecimal xIncrement = xAbs.divide(degree, 6, BigDecimal.ROUND_DOWN);
		//维度实际增量
		BigDecimal yIncrement = yAbs.divide(degree, 6, BigDecimal.ROUND_DOWN);
		for(int i=0;i<degree.intValue();i++){
			if(xAddTrue){
				x1 = x1.add(xIncrement);
			}else{
				x1 = x1.subtract(xIncrement);
			}
			if(yAddTrue){
				y1 = y1.add(yIncrement);
			}else{
				y1 = y1.subtract(yIncrement);
			}
			
			System.out.println("x:"+x1.setScale(6, BigDecimal.ROUND_HALF_UP)+" ,y:"+y1.setScale(6, BigDecimal.ROUND_HALF_UP));
		}
	}

  

posted on 2014-01-15 13:16  jackvc  阅读(395)  评论(0编辑  收藏  举报

导航