zoukankan      html  css  js  c++  java
  • 计算GPS WGS_84 两点的距离 更加细腻的算法

    上面的一篇博客,两点距离比较粗糙,现贴一篇更加细腻的算法

    wgs84PointsDistance = function(fromPoint, toPoint) {
    	if(arguments.length != 2) {
    		return 0;
    	}
    	lon1 = fromPoint.x;
    	lat1 = fromPoint.y;
    	lon2 = toPoint.x;
    	lat2 = toPoint.y;
    	var a = 6378137, b = 6356752.3142, f = 1 / 298.257223563;
    	var L = (lon2 - lon1).toRad();
    	var U1 = Math.atan((1 - f) * Math.tan(lat1.toRad()));
    	var U2 = Math.atan((1 - f) * Math.tan(lat2.toRad()));
    	var sinU1 = Math.sin(U1), cosU1 = Math.cos(U1);
    	var sinU2 = Math.sin(U2), cosU2 = Math.cos(U2);
    	var lambda = L, lambdaP, iterLimit = 100;
      	do {
    		var sinLambda = Math.sin(lambda), cosLambda = Math.cos(lambda);
    		var sinSigma = Math.sqrt((cosU2 * sinLambda) * (cosU2 * sinLambda) + (cosU1 * sinU2 - sinU1 * cosU2 * cosLambda) * (cosU1 * sinU2 - sinU1 * cosU2 * cosLambda));
    		if(sinSigma == 0)
    			return 0;
    		var cosSigma = sinU1 * sinU2 + cosU1 * cosU2 * cosLambda;
    		var sigma = Math.atan2(sinSigma, cosSigma);
    		var sinAlpha = cosU1 * cosU2 * sinLambda / sinSigma;
    		var cosSqAlpha = 1 - sinAlpha * sinAlpha;
    		var cos2SigmaM = cosSigma - 2 * sinU1 * sinU2 / cosSqAlpha;
    		if(isNaN(cos2SigmaM))
    			cos2SigmaM = 0;
    		var C = f / 16 * cosSqAlpha * (4 + f * (4 - 3 * cosSqAlpha));
    		lambdaP = lambda;
    		lambda = L + (1 - C) * f * sinAlpha * (sigma + C * sinSigma * (cos2SigmaM + C * cosSigma * (-1 + 2 * cos2SigmaM * cos2SigmaM)));
        } while (Math.abs(lambda-lambdaP) > (1e-12) && --iterLimit>0);
    	if(iterLimit == 0) {
    		return NaN
    	}
    	var uSq = cosSqAlpha * (a * a - b * b) / (b * b);
    	var A = 1 + uSq / 16384 * (4096 + uSq * (-768 + uSq * (320 - 175 * uSq)));
    	var B = uSq / 1024 * (256 + uSq * (-128 + uSq * (74 - 47 * uSq)));
    	var deltaSigma = B * sinSigma * (cos2SigmaM + B / 4 * (cosSigma * (-1 + 2 * cos2SigmaM * cos2SigmaM) - B / 6 * cos2SigmaM * (-3 + 4 * sinSigma * sinSigma) * (-3 + 4 * cos2SigmaM * cos2SigmaM)));
    	var s = b * A * (sigma - deltaSigma);
    	var fwdAz = Math.atan2(cosU2 * sinLambda, cosU1 * sinU2 - sinU1 * cosU2 * cosLambda);
    	var revAz = Math.atan2(cosU1 * sinLambda, -sinU1 * cosU2 + cosU1 * sinU2 * cosLambda);
    	return s;
    }
    

      

    转载请注明出处,http://www.cnblogs.com/HPhone/

    独立博客启用 万马奔腾-让现在的自己喜欢未来的你

    微博欢迎关注 webgis

  • 相关阅读:
    操作系统学习笔记:银行家算法的回顾和训练
    操作系统学习笔记:内存学习随笔
    操作系统笔记:内存的连续管理
    操作系统笔记:内存的离散管理
    操作系统:内存管理复习ing之页面置换算法
    马原学习日记1:实践
    bootstrap简单教程
    css-6(媒体识别)
    css-5(弹性盒子)
    css-3(旋转+过渡)
  • 原文地址:https://www.cnblogs.com/HPhone/p/2803672.html
Copyright © 2011-2022 走看看