2011-10-18 2 views
0

다음을 수행하려면 C#에서 함수가 필요합니다. gps- 점 A에서 GPS 점 B 방향으로 50m 이동하고 GPS를 계산합니다 그 점에 대해 - 코디네이트.LatLonA에서 LatLonB까지 (WGS84) "이동"# 미터

function LatLon MoveTowards(LatLon A, LatLon B, double MetersOverGround) 
{ 
    //code here 
} 

이 함수가 좌표를 반환 A로부터 멀리 X 미터입니다 : 내가하고 싶은 것은이 같은 함수가

LatLon LatLonA = new LatLon(51.83966, 5.04631); // Latitude 51.83966, Longitude 5.04631 
LatLon LatLonB = new LatLon(51.84172, 5.01961); // Latitude 51.84172, Longitude 5.01961 

입니다 :

는 예를 들어 나는 두 개의 좌표를 가지고 B 방향으로

+0

내가 전에 점 사이의 거리를 계산하는 하버 사인 공식을 사용했지만, 나는 내가 사용했습니다 – frankhommers

답변

2

지구는 구형이 아니며 타원도 아닙니다. 상업 도서관을 구입하지 않고 희망 할 수있는 최선의 방법은 근사치 (대부분의 사람들에게 충분 함)입니다.

Haversine formula을 먼저 살펴보면 this page이 큰 도움이 될 것입니다. 큰 성공을 여기

+0

... 그냥 부탁 해요 방식으로 작동하는 알고리즘을 마무리하는 방법을 잘 모르겠어요 포인트 사이의 거리를 계산하기위한 Haversine 공식. 근사치이면 충분합니다. – frankhommers

0

또는 상업용 라이브러리를 원한다면, 내가 사용하고 ProLat 당신이 원하는합니다. Math.Atan2을 사용하여 A-to-B 벡터의 방정식을 얻고 bearing 매개 변수를 얻으십시오.

/// <summary> 
    /// Calculates the end-point from a given source at a given range (meters) and bearing (degrees). 
    /// This methods uses simple geometry equations to calculate the end-point. 
    /// </summary> 
    /// <param name="source">Point of origin</param> 
    /// <param name="range">Range in meters</param> 
    /// <param name="bearing">Bearing in degrees</param> 
    /// <returns>End-point from the source given the desired range and bearing.</returns> 
    public static PointLatLng CalculateDerivedPosition(PointLatLng source, double range, double bearing) 
    { 
     double latA = source.Lat * DEGREES_TO_RADIANS; 
     double lonA = source.Lng * DEGREES_TO_RADIANS; 
     double angularDistance = range/EARTH_RADIUS_M; 
     double trueCourse = bearing * DEGREES_TO_RADIANS; 

     double lat = Math.Asin(
      Math.Sin(latA) * Math.Cos(angularDistance) + 
      Math.Cos(latA) * Math.Sin(angularDistance) * Math.Cos(trueCourse)); 

     double dlon = Math.Atan2(
      Math.Sin(trueCourse) * Math.Sin(angularDistance) * Math.Cos(latA), 
      Math.Cos(angularDistance) - Math.Sin(latA) * Math.Sin(lat)); 

     double lon = ((lonA + dlon + Math.PI) % (Math.PI * 2)) - Math.PI; 

     return new PointLatLng(
      lat/DEGREES_TO_RADIANS, 
      lon/DEGREES_TO_RADIANS); 
    }