如何根据距离和第一个经纬度点得到下一个经纬度位置?
How to get next latitude and longtitude position acording to distance and first latitude, longtitude point?
我需要根据指定的距离查找纬度和经度。例如,我有 50 厘米的距离和一个纬度和经度点,我想找到距离我的第一个点 50 厘米远的下一个点是什么?
嘿,我得到了解决方案,我已经按照 https://www.movable-type.co.uk/scripts/latlong.html 的计算实现了这个,并在 c#
中实现了这个计算
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;
}
private double GetBearing(PointLatLng pt1, PointLatLng pt2)
{
double x = Math.Cos(DegreesToRadians(pt1.Lat)) * Math.Sin(DegreesToRadians(pt2.Lat)) - Math.Sin(DegreesToRadians(pt1.Lat)) * Math.Cos(DegreesToRadians(pt2.Lat)) * Math.Cos(DegreesToRadians(pt2.Lng - pt1.Lng));
double y = Math.Sin(DegreesToRadians(pt2.Lng - pt1.Lng)) * Math.Cos(DegreesToRadians(pt2.Lat));
return (Math.Atan2(y, x) + Math.PI * 2) % (Math.PI * 2);
}
public static PointLatLng FindPointAtDistanceFrom(PointLatLng startPoint, double initialBearingRadians)
{
double distanceKilometres = 0.0005; //50cm = 0.0005Km;
const double radiusEarthKilometres = 6371.01;
var distRatio = distanceKilometres / radiusEarthKilometres;
var distRatioSine = Math.Sin(distRatio);
var distRatioCosine = Math.Cos(distRatio);
var startLatRad = DegreesToRadians(startPoint.Lat);
var startLonRad = DegreesToRadians(startPoint.Lng);
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 PointLatLng
{
Lat = RadiansToDegrees(endLatRads),
Lng = RadiansToDegrees(endLonRads)
};
}
此代码的用法是:
//Get Angle of point
var bearing = GetBearing(polyStartPoint, polyEndPoint);
//Get Point from 50cm away for specified point
var nextStartPoint = FindPointAtDistanceFrom(polyStartPoint, bearing);
我需要根据指定的距离查找纬度和经度。例如,我有 50 厘米的距离和一个纬度和经度点,我想找到距离我的第一个点 50 厘米远的下一个点是什么?
嘿,我得到了解决方案,我已经按照 https://www.movable-type.co.uk/scripts/latlong.html 的计算实现了这个,并在 c#
中实现了这个计算 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;
}
private double GetBearing(PointLatLng pt1, PointLatLng pt2)
{
double x = Math.Cos(DegreesToRadians(pt1.Lat)) * Math.Sin(DegreesToRadians(pt2.Lat)) - Math.Sin(DegreesToRadians(pt1.Lat)) * Math.Cos(DegreesToRadians(pt2.Lat)) * Math.Cos(DegreesToRadians(pt2.Lng - pt1.Lng));
double y = Math.Sin(DegreesToRadians(pt2.Lng - pt1.Lng)) * Math.Cos(DegreesToRadians(pt2.Lat));
return (Math.Atan2(y, x) + Math.PI * 2) % (Math.PI * 2);
}
public static PointLatLng FindPointAtDistanceFrom(PointLatLng startPoint, double initialBearingRadians)
{
double distanceKilometres = 0.0005; //50cm = 0.0005Km;
const double radiusEarthKilometres = 6371.01;
var distRatio = distanceKilometres / radiusEarthKilometres;
var distRatioSine = Math.Sin(distRatio);
var distRatioCosine = Math.Cos(distRatio);
var startLatRad = DegreesToRadians(startPoint.Lat);
var startLonRad = DegreesToRadians(startPoint.Lng);
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 PointLatLng
{
Lat = RadiansToDegrees(endLatRads),
Lng = RadiansToDegrees(endLonRads)
};
}
此代码的用法是:
//Get Angle of point
var bearing = GetBearing(polyStartPoint, polyEndPoint);
//Get Point from 50cm away for specified point
var nextStartPoint = FindPointAtDistanceFrom(polyStartPoint, bearing);