http://www.movable-type.co.uk/scripts/latlong.html
当我尝试通过代码实现相同的时候,我没有得到正确的结果.
以下是我的代码 –
private GLatLng poinTradialdistance(double lat1,double lon1,double radianbearing,double radialdistance) { double rEarth = 6371.01; lat1 = DegreetoRadian(lat1); lon1 = DegreetoRadian(lon1); radianbearing = DegreetoRadian(radianbearing); radialdistance = radialdistance / rEarth; double lat = Math.Asin(Math.Sin(lat1) * Math.Cos(radialdistance) + Math.Cos(lat1) * Math.Sin(radialdistance) * Math.Cos(radianbearing)); double lon; if (Math.Cos(lat) == 0) { // Endpoint a pole lon = lon1; } else { lon = ((lon1 - Math.Asin(Math.Sin(radianbearing) * Math.Sin(radialdistance) / Math.Cos(lat)) + Math.PI) % (2 * Math.PI)) - Math.PI; } lat = RadianToDegree(lat); lon = RadianToDegree(lon); GLatLng newLatLng = new GLatLng(lat,lon); return newLatLng; } public double bearing(double lat1,double long1,double lat2,double long2) { //Convert input values to radians lat1 = DegreetoRadian(lat1); long1 = DegreetoRadian(long1); lat2 = DegreetoRadian(lat2); long2 = DegreetoRadian(long2); double deltaLong = long2 - long1; double y = Math.Sin(deltaLong) * Math.Cos(lat2); double x = Math.Cos(lat1) * Math.Sin(lat2) - Math.Sin(lat1) * Math.Cos(lat2) * Math.Cos(deltaLong); double bearing = Math.atan2(y,x); return bearing; } public double DegreetoRadian(double angle) { return Math.PI * angle / 180.0; } public double RadianToDegree(double angle) { return 180.0 * angle / Math.PI; }
从主程序,我调用子程序如下 –
double bearing = bearing(-41.294444,174.814444,-40.90521,175.6604);GLatLng endLatLng = poinTradialdistance(-41.294444,bearing,80);
我得到以下结果 –
bearing=1.02749621782165endLatLng=-40.5751022737927,174.797458881699
我期望的答案是-40.939722,175.646389(从上面的网站链接).
任何人都可以建议我在代码中出现什么错误?
@H_404_22@解决方法 这是一些实现你想要做的代码.public static Geolocation FindPointAtdistanceFrom(Geolocation startPoint,double initialbearingradians,double distanceKilometres){ const double radiusEarthKilometres = 6371.01; var distRatio = distanceKilometres / radiusEarthKilometres; var distRatioSine = Math.Sin(distRatio); var distRatioCosine = Math.Cos(distRatio); var startLaTrad = degreesToradians(startPoint.Latitude); var startLonRad = degreesToradians(startPoint.Longitude); var startLatCos = Math.Cos(startLaTrad); var startLatSin = Math.Sin(startLaTrad); var endLaTrads = Math.Asin((startLatSin * distRatioCosine) + (startLatCos * distRatioSine * Math.Cos(initialbearingradians))); var endLonRads = startLonRad + Math.atan2( Math.Sin(initialbearingradians) * distRatioSine * startLatCos,distRatioCosine - startLatSin * Math.Sin(endLaTrads)); return new Geolocation { Latitude = radiansTodegrees(endLaTrads),Longitude = radiansTodegrees(endLonRads) };}public struct Geolocation{ public double Latitude { get; set; } public double Longitude { get; set; }}public static double degreesToradians(double degrees){ const double degToRadFactor = Math.PI / 180; return degrees * degToRadFactor;}public static double radiansTodegrees(double radians){ const double radToDegFactor = 180 / Math.PI; return radians * radToDegFactor;}@H_404_22@ @H_404_22@ 总结
以上是内存溢出为你收集整理的c# – 计算给定距离,轴承,起点的端点全部内容,希望文章能够帮你解决c# – 计算给定距离,轴承,起点的端点所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)