c# - 如何计算转弯方向

标签 c# geometry navigation geolocation gis

我有一个三个经纬度坐标组成两条线段 A 到 B 到 C。我还找到了一个函数,它可以以 -180 到 180 的方式返回线段 A-B 或 B-C 的北方位。但是,我无法确定汽车何时从 A 到达 B,它应该向右转还是向左转以继续前往 C。

最佳答案

编辑:之前的答案是错误的。现在这是正确的

public Direction GetDirection(Point a, Point b, Point c)
{
    double theta1 = GetAngle(a, b); 
    double theta2 = GetAngle(b, c);
    double delta = NormalizeAngle(theta2 - theta1);

    if ( delta == 0 )
        return Direction.Straight;
    else if ( delta == Math.PI )
        return Direction.Backwards;
    else if ( delta < Math.PI )
        return Direction.Left;
    else return Direction.Right;
}

private Double GetAngle(Point p1, Point p2)
{
    Double angleFromXAxis = Math.Atan ((p2.Y - p1.Y ) / (p2.X - p1.X ) ); // where y = m * x + K
    return  p2.X - p1.X < 0 ? m + Math.PI : m ); // The will go to the correct Quadrant
}

private Double NormalizeAngle(Double angle)
{
    return angle < 0 ? angle + 2 * Math.PI : angle; //This will make sure angle is [0..2PI]
}

关于c# - 如何计算转弯方向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3419341/

相关文章:

opengl 不同颜色的三角扇

检查点是否在矩形的给定距离内?

jquery - 响应式导航

razor - 在 .Net Core 中导航到另一个文件夹中的页面

c# - Windows 窗体应用程序命令行参数

c# - MVP:一种复杂表单(winforms)的多个 View /演示者?

c# - Simple Injector 使用元数据注册多种类型的相同接口(interface)

r - 如何根据R中的曼哈顿距离计算Voronoi镶嵌

html - 更改导航按钮的外观以响应滚动

c# - 无法在 C# 中打开 Excel 文件