如何计算转弯方向

VOX*_*VOX 5 c# navigation gis geometry geolocation

我有一个三个lat-lon坐标组成两个线段A到B到C.我还发现了一个函数,它可以以-180到180的方式返回线段AB或BC的北轴承.但是,我很难确定汽车何时从A到B,如果它向右或向左转到继续到C.

Car*_*ñoz 9

编辑:以前的答案是错的.现在这是正确的

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]
}
Run Code Online (Sandbox Code Playgroud)