■ 각도 구하기

----------------------------------------------------------------------------------------------------

using System;

 

#region 각도 구하기 - GetDegree(startLatitude, startLongitude, endLatitude, endLongitude)

 

/// <summary>

/// 각도 구하기

/// </summary>

/// <param name="startLatitude">시작 위도</param>

/// <param name="startLongitude">시작 경도</param>

/// <param name="endLatitude">종료 위도</param>

/// <param name="endLongitude">종료 경도</param>

/// <returns>각도</returns>

public double GetDegree(double startLatitude, double startLongitude, double endLatitude, double endLongitude)

{

    double startLatitudeRadian  = startLatitude  * Math.PI / 180d;

    double startLongitudeRadian = startLongitude * Math.PI / 180d;

    double endLatitudeRadian    = endLatitude    * Math.PI / 180d;

    double endLongitudeRadian   = endLongitude   * Math.PI / 180d;

 

    double distance = Math.Acos(Math.Sin(startLatitudeRadian) * Math.Sin(endLatitudeRadian) +

        Math.Cos(startLatitudeRadian) * Math.Cos(endLatitudeRadian) * Math.Cos(endLongitudeRadian -

        startLongitudeRadian));

 

    double degree = Math.Acos((Math.Sin(endLatitudeRadian) - Math.Sin(startLatitudeRadian) * Math.Cos(distance)) /

        (Math.Cos(startLatitudeRadian) * Math.Sin(distance))) * (180d / Math.PI);

 

    if((endLongitudeRadian - startLongitudeRadian) < 0d)

    {

        degree = 360 - degree;

    }

 

    return degree;

}

 

#endregion

----------------------------------------------------------------------------------------------------

Posted by 사용자 icodebroker
TAG

댓글을 달아 주세요