Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/307.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 两坐标计算之间的轴承输出_C#_Trigonometry_Gis - Fatal编程技术网

C# 两坐标计算之间的轴承输出

C# 两坐标计算之间的轴承输出,c#,trigonometry,gis,C#,Trigonometry,Gis,我有一个方法,假设计算两个地理坐标之间的方位角(40.7486,-73.9864示例格式) 但是,我遇到了一个问题,即它计算的标题与我使用经过测试的应用程序计算的标题不同 例如,以下两点之间的初始方位角为074度,但我的方法返回047度。 40.7486,-73.9864 40.9486,-72.9866 下面是相关的代码片段 /// <summary> /// Calculate the inital bearing between two Locati

我有一个方法,假设计算两个地理坐标之间的方位角(40.7486,-73.9864示例格式)

但是,我遇到了一个问题,即它计算的标题与我使用经过测试的应用程序计算的标题不同

例如,以下两点之间的初始方位角为074度,但我的方法返回047度。
40.7486,-73.9864

40.9486,-72.9866

下面是相关的代码片段

        /// <summary>
    /// Calculate the inital bearing between two Locations
    /// </summary>
    /// <param name="pointA"></param>
    /// <param name="pointB"></param>
    /// <param name="headingType"></param>
    /// <returns></returns>
    public static double BearingToLocation(Location pointA, Location pointB)
    {
        // Convert both locations from degrees to radians
        pointA = LocationToRad(pointA);
        pointB = LocationToRad(pointB);

        double partOne = exMath.Sin(pointB.Longitude - pointA.Longitude) * exMath.Cos(pointB.Latitude);
        double partTwo = exMath.Cos(pointA.Latitude) * exMath.Sin(pointB.Latitude) - exMath.Sin(pointA.Latitude) * exMath.Cos(pointB.Latitude) * exMath.Cos(pointB.Longitude - pointA.Longitude);
        double heading = AdditionalMath.ToDeg(exMath.Atan2(partOne, partTwo) % 2 * exMath.PI);

        // Solve for compass wrap around
        if (heading < 0)
            heading += 360;

        return heading;
    }

    /// <summary>
    /// Return a new location in radians
    /// </summary>
    /// <param name="pointA"></param>
    /// <returns></returns>
    public static Location LocationToRad(Location pointA)
    {
        return new Location(AdditionalMath.ToRad(pointA.Latitude), AdditionalMath.ToRad(pointA.Longitude), pointA.Altitude);
    }

}

/// <summary>
/// Misc. math functions not available in Elze Kool's lib
/// </summary>
public static class AdditionalMath
{
    /// <summary>
    /// Degrees to radians
    /// </summary>
    /// <param name="x"></param>
    /// <returns></returns>
    public static double ToRad(double x)
    {
        return exMath.PI * x / 180.00F;
    }

    /// <summary>
    /// Radians to degrees
    /// </summary>
    /// <param name="x"></param>
    /// <returns></returns>
    public static double ToDeg(double x)
    {
        return x * 180.00F / exMath.PI;
    }
}
//
///计算两个位置之间的初始轴承
/// 
/// 
/// 
/// 
/// 
公共静态双轴承位置(位置点A、位置点B)
{
//将两个位置从度转换为弧度
点A=位置TORAD(点A);
点B=位置TORAD(点B);
double partOne=exMath.Sin(点B.经度-点A.经度)*exMath.Cos(点B.纬度);
双部件2=exMath.Cos(点A.纬度)*exMath.Sin(点B.纬度)-exMath.Sin(点A.纬度)*exMath.Cos(点B.纬度)*exMath.Cos(点B.经度-点A.经度);
双标题=AdditionalMath.ToDeg(exMath.Atan2(Part1,Part2)%2*exMath.PI);
//求解指南针环绕
如果(标题<0)
航向+=360;
返回航向;
}
/// 
///以弧度返回新位置
/// 
/// 
/// 
公共静态位置LocationToRad(位置点A)
{
返回新位置(AdditionalMath.ToRad(pointA.Latitude)、AdditionalMath.ToRad(pointA.Latitude)、pointA.Altitude);
}
}
/// 
///杂项。Elze Kool的库中没有数学函数
/// 
公共静态类AdditionalMath
{
/// 
///度到弧度
/// 
/// 
/// 
公共静态双ToRad(双x)
{
返回exMath.PI*x/180.00F;
}
/// 
///弧度
/// 
/// 
/// 
公共静态双ToDeg(双x)
{
返回x*180.00F/exMath.PI;
}
}

有人能看到这个问题吗?我仔细查看了一下,没有找到问题。

这行中的
%
看起来可疑:

    double heading = AdditionalMath.ToDeg(exMath.Atan2(partOne, partTwo) % 2 * exMath.PI);

%
在这行中看起来可疑:

    double heading = AdditionalMath.ToDeg(exMath.Atan2(partOne, partTwo) % 2 * exMath.PI);

成功了!非常感谢!!根据行应该是:双标题=AdditionalMath.ToDeg(exMath.Atan2(第一部分,第二部分));成功了!非常感谢!!根据行应该是:双标题=AdditionalMath.ToDeg(exMath.Atan2(第一部分,第二部分));最后是什么?有用的代码…实际上是数学库。我使用的原始版本是Elze Kool写的,它有几个问题。最后,我放弃了它,使用了一个在我的设备上实现了“诞生”的工具(GHI electronics FEZ Domino),最终解决了什么问题?有用的代码…实际上是数学库。我使用的原始版本是Elze Kool写的,它有几个问题。最后,我放弃了它,使用了一个在我的设备上实现了耶稣诞生的(GHI electronics FEZ Domino)