source:subversion/applications/routing/pyroute/geometry.py@5740

Last change on this file since 5740 was 5740, checked in by ojw, 12 years ago

try using spherical law of cosines to do distances

File size: 1.5 KB
Line
1#!/usr/bin/python
2#-----------------------------------------------------------------------------
3# Handles geometry on the earth's surface (e.g. bearing/distance)
4#
5# Usage:
6#   (library code)
7#-----------------------------------------------------------------------------
9#
10# This program is free software: you can redistribute it and/or modify
12# the Free Software Foundation, either version 3 of the License, or
13# (at your option) any later version.
14#
15# This program is distributed in the hope that it will be useful,
16# but WITHOUT ANY WARRANTY; without even the implied warranty of
17# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18# GNU General Public License for more details.
19#
20# You should have received a copy of the GNU General Public License
21# along with this program.  If not, see <http://www.gnu.org/licenses/>.
22#-----------------------------------------------------------------------------
23from math import *
24
25def bearing(a,b):
26    dlat = radians(b[0] - a[0])
27    dlon = radians(b[1] - a[1])
28
29    dlon = dlon * cos(radians(a[0]))
30
31    return(degrees(atan2(dlon, dlat)))
32
33def distance(a,b):