• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeedu API Reference
  • KDE Home
  • Contact Us
 

marble

  • sources
  • kde-4.12
  • kdeedu
  • marble
  • src
  • lib
  • marble
  • routing
  • instructions
RoutingPoint.cpp
Go to the documentation of this file.
1 //
2 // This file is part of the Marble Virtual Globe.
3 //
4 // This program is free software licensed under the GNU LGPL. You can
5 // find a copy of this license in LICENSE.txt in the top directory of
6 // the source code.
7 //
8 // Copyright 2010 Dennis Nienhüser <earthwings@gentoo.org>
9 //
10 
11 #include "RoutingPoint.h"
12 
13 #include <cmath>
14 
15 namespace Marble
16 {
17 
18 RoutingPoint::RoutingPoint( qreal lon, qreal lat ) :
19  m_lon( lon), m_lonRad( lon * M_PI / 180.0 ),
20  m_lat( lat ), m_latRad( lat * M_PI / 180.0 )
21 {
22  // nothing to do
23 }
24 
25 qreal RoutingPoint::lon() const
26 {
27  return m_lon;
28 }
29 
30 qreal RoutingPoint::lat() const
31 {
32  return m_lat;
33 }
34 
35 // Code based on http://www.movable-type.co.uk/scripts/latlong.html
36 qreal RoutingPoint::bearing( const RoutingPoint &other ) const
37 {
38  qreal deltaLon = other.m_lonRad - m_lonRad;
39  qreal y = sin( deltaLon ) * cos( other.m_latRad );
40  qreal x = cos( m_latRad ) * sin( other.m_latRad ) -
41  sin( m_latRad ) * cos( other.m_latRad ) * cos( deltaLon );
42  return atan2( y, x );
43 }
44 
45 // From MarbleMath::distanceSphere
46 qreal RoutingPoint::distance( const RoutingPoint &other ) const
47 {
48  qreal h1 = sin( 0.5 * ( other.m_latRad - m_latRad ) );
49  qreal h2 = sin( 0.5 * ( other.m_lonRad - m_lonRad ) );
50  qreal d = h1 * h1 + cos( m_latRad ) * cos( other.m_latRad ) * h2 * h2;
51 
52  return 6378000.0 * 2.0 * atan2( sqrt( d ), sqrt( 1.0 - d ) );
53 }
54 
55 QTextStream& operator<<( QTextStream& stream, const RoutingPoint &p )
56 {
57  stream << "(" << p.lon() << ", " << p.lat() << ")";
58  return stream;
59 }
60 
61 } // namespace Marble
Marble::RoutingPoint::lat
qreal lat() const
Latitude of the point.
Definition: RoutingPoint.cpp:30
Marble::RoutingPoint::lon
qreal lon() const
Longitude of the point.
Definition: RoutingPoint.cpp:25
Marble::RoutingPoint::RoutingPoint
RoutingPoint(qreal lon=0.0, qreal lat=0.0)
Definition: RoutingPoint.cpp:18
RoutingPoint.h
Marble::RoutingPoint::distance
qreal distance(const RoutingPoint &other) const
Calculates the distance in meter between this point and the given other point.
Definition: RoutingPoint.cpp:46
Marble::RoutingPoint
There are many Point classes, but this is mine.
Definition: RoutingPoint.h:24
Marble::RoutingPoint::bearing
qreal bearing(const RoutingPoint &other) const
Calculates the bearing of the line defined by this point and the given other point.
Definition: RoutingPoint.cpp:36
M_PI
#define M_PI
Definition: GeoDataCoordinates.h:26
Marble::operator<<
QTextStream & operator<<(QTextStream &stream, const RoutingInstruction &i)
Definition: RoutingInstruction.cpp:455
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:38:52 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

marble

Skip menu "marble"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • kstars
  • libkdeedu
  •   keduvocdocument
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal