# Marble

RoutingPoint.cpp
2//
3// SPDX-FileCopyrightText: 2010 Dennis NienhÃ¼ser <nienhueser@kde.org>
4//
5
6#include "RoutingPoint.h"
7
8#include <QTextStream>
9
10#include <cmath>
11
12namespace Marble
13{
14
15RoutingPoint::RoutingPoint( qreal lon, qreal lat ) :
16 m_lon( lon), m_lonRad( lon * M_PI / 180.0 ),
17 m_lat( lat ), m_latRad( lat * M_PI / 180.0 )
18{
19 // nothing to do
20}
21
22qreal RoutingPoint::lon() const
23{
24 return m_lon;
25}
26
27qreal RoutingPoint::lat() const
28{
29 return m_lat;
30}
31
32// Code based on https://www.movable-type.co.uk/scripts/latlong.html
33qreal RoutingPoint::bearing( const RoutingPoint &other ) const
34{
36 qreal y = sin( deltaLon ) * cos( other.m_latRad );
37 qreal x = cos( m_latRad ) * sin( other.m_latRad ) -
38 sin( m_latRad ) * cos( other.m_latRad ) * cos( deltaLon );
39 return atan2( y, x );
40}
41
42// From MarbleMath::distanceSphere
43qreal RoutingPoint::distance( const RoutingPoint &other ) const
44{
45 qreal h1 = sin( 0.5 * ( other.m_latRad - m_latRad ) );
46 qreal h2 = sin( 0.5 * ( other.m_lonRad - m_lonRad ) );
47 qreal d = h1 * h1 + cos( m_latRad ) * cos( other.m_latRad ) * h2 * h2;
48
49 return 6378137.0 * 2.0 * atan2( sqrt( d ), sqrt( 1.0 - d ) );
50}
51
52QTextStream& operator<<( QTextStream& stream, const RoutingPoint &p )
53{
54 stream << "(" << p.lon() << ", " << p.lat() << ")";
55 return stream;
56}
57
58} // namespace Marble
There are many Point classes, but this is mine.
qreal lon() const
Longitude of the point.
qreal lat() const
Latitude of the point.
Binds a QML item to a specific geodetic location in screen coordinates.
This file is part of the KDE documentation.