Esempio n. 1
0
    /// <summary>
    /// Gets the priority of the next segment of road where vehicles on lower priority roads will need to give way to vehicles on higher priority roads
    ///
    /// lowest prioirty
    /// 1 - one way E-W
    /// 2 - one way N-S
    /// 3 - two way E-W
    /// 4 - two way N-S
    /// </summary>
    /// <returns>The priority of the next segment of road to travel</returns>
    private void getBearingAndPriority()
    {
        if (currentNode >= pathList.Count - 2 || currentNode == 0)
        {
            roadPriority = 5;
            return;
        }

        Graph.Node currNode = g.nodeIdNodeDict[pathList[currentNode]];
        Graph.Node prevNode = g.nodeIdNodeDict[pathList[currentNode - 1]];

        double startLat = prevNode.lat;
        double startLon = prevNode.lon;
        double endLat   = currNode.lat;
        double endLon   = currNode.lon;

        startLat = startLat * Math.PI / 180;
        startLon = startLon * Math.PI / 180;
        endLat   = endLat * Math.PI / 180;
        endLon   = endLon * Math.PI / 180;

        double x     = Math.Sin(endLon - startLon) * Math.Cos(endLat);
        double y     = Math.Cos(startLat) * Math.Sin(endLat) - Math.Sin(startLat) * Math.Cos(endLat) * Math.Cos(endLat - startLat);
        double theta = Math.Atan2(y, x);
        double brng  = (theta * 180 / Math.PI + 360) % 360;

        if (brng == 0)
        {
            brng = 360;
        }

        if (brng >= 315 || brng < 45)
        {
            currentBearing = bearing.north;
        }
        else if (brng >= 45 && brng < 135)
        {
            currentBearing = bearing.east;
        }
        else if (brng >= 135 && brng < 225)
        {
            currentBearing = bearing.south;
        }
        else
        {
            currentBearing = bearing.west;
        }

        bool isOneWay = onOneWay();

        if (currentBearing == bearing.east || currentBearing == bearing.west)
        {
            roadPriority = isOneWay ? 1 : 3;
        }
        else
        {
            roadPriority = isOneWay ? 2 : 5;
        }
    }
Esempio n. 2
0
 public BearingVM()
 {
     TheEntity = new bearing();
     TheEntity.MetaSetUp();
 }