Project-OSRM / osrm-backend

Open Source Routing Machine - C++ backend
http://map.project-osrm.org
BSD 2-Clause "Simplified" License
6.29k stars 3.32k forks source link

how to understand bearing ? #5612

Closed bsnyh closed 1 month ago

bsnyh commented 4 years ago

I'm confused about the following two functions defined in bearing.hpp.

// reverse the direction;
//I think bearing of a location a, is like putting the compass at location a, and go with a direction /angle with respect to the north line (which is treated like 0)
inline double reverse(const double bearing)
{
    if (bearing >= 180)
        return bearing - 180.;
    return bearing + 180;
}

// Compute the angle between two bearings on a normal turn circle
//
//      Bearings                      Angles
//
//            0                              180
//   315         45               225       135
//
// 270     x       90           270     x      90
//
//   225        135               315        45
//         180                                0
//
// A turn from north to north-east offerst bearing 0 and 45 has to be translated
// into a turn of 135 degrees. The same holdes for 90 - 135 (east to south
// east).
// For north, the transformation works by angle = 540 (360 + 180) - exit_bearing
// % 360;
// All other cases are handled by first rotating both bearings to an
// entry_bearing of 0.
inline double angleBetween(const double entry_bearing, const double exit_bearing)
{
    return std::fmod(entry_bearing - exit_bearing + 540., 360.);
}

} // namespace bearing

// compute the minimum distance in degree between two angles/bearings
inline double angularDeviation(const double angle_or_bearing, const double from)
{
    const double deviation = std::abs(angle_or_bearing - from);
    return std::min(360 - deviation, deviation);
}

I understand the Bearing figure above, but not the other Angles figure. Any comments are greatly appreciated.

PS: I'm working on the details of this software as much as I can lately. If anyone else would like to work on it together, feel free to drop me a message or not.

github-actions[bot] commented 2 months ago

This issue seems to be stale. It will be closed in 30 days if no further activity occurs.