QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
QGCGeoBoundingCube.cc
Go to the documentation of this file.
2#include <QtCore/QDebug>
3#include <cmath>
4
5double QGCGeoBoundingCube::MaxAlt = 1000000.0;
6double QGCGeoBoundingCube::MinAlt = -1000000.0;
9double QGCGeoBoundingCube::MaxWest = -180.0;
10double QGCGeoBoundingCube::MaxEast = 180.0;
11
12//-----------------------------------------------------------------------------
14 : QObject(parent)
15{
16 reset();
17}
18
19//-----------------------------------------------------------------------------
20bool
22{
23 return pointNW.isValid() && pointSE.isValid() && pointNW.latitude() != MaxSouth && pointSE.latitude() != MaxNorth && \
24 pointNW.longitude() != MaxEast && pointSE.longitude() != MaxWest && pointNW.altitude() < MaxAlt && pointSE.altitude() > MinAlt;
25}
26
27//-----------------------------------------------------------------------------
28void
29QGCGeoBoundingCube::reset()
30{
31 pointNW = QGeoCoordinate(MaxSouth, MaxEast, MaxAlt);
32 pointSE = QGeoCoordinate(MaxNorth, MaxWest, MinAlt);
33}
34
35//-----------------------------------------------------------------------------
36QGeoCoordinate
38{
39 if(!isValid())
40 return QGeoCoordinate();
41 double lat = (((pointNW.latitude() + 90.0) + (pointSE.latitude() + 90.0)) / 2.0) - 90.0;
42 double lon = (((pointNW.longitude() + 180.0) + (pointSE.longitude() + 180.0)) / 2.0) - 180.0;
43 double alt = (pointNW.altitude() + pointSE.altitude()) / 2.0;
44 return QGeoCoordinate(lat, lon, alt);
45}
46
47//-----------------------------------------------------------------------------
48QList<QGeoCoordinate>
50{
51 QList<QGeoCoordinate> coords;
52 if(isValid()) {
53 //-- Should we clip it?
54 if(clipTo > 0.0 && area() > clipTo) {
55 //-- Clip it to a square of given area centered on current bounding box center.
56 double side = sqrt(clipTo);
57 QGeoCoordinate c = center();
58 double a = pow((side * 0.5), 2);
59 double h = sqrt(a + a) * 1000.0;
60 QGeoCoordinate nw = c.atDistanceAndAzimuth(h, 315.0);
61 QGeoCoordinate se = c.atDistanceAndAzimuth(h, 135.0);
62 coords.append(QGeoCoordinate(nw.latitude(), nw.longitude(), se.altitude()));
63 coords.append(QGeoCoordinate(nw.latitude(), se.longitude(), se.altitude()));
64 coords.append(QGeoCoordinate(se.latitude(), se.longitude(), se.altitude()));
65 coords.append(QGeoCoordinate(se.latitude(), nw.longitude(), se.altitude()));
66 coords.append(QGeoCoordinate(nw.latitude(), nw.longitude(), se.altitude()));
67 } else {
68 coords.append(QGeoCoordinate(pointNW.latitude(), pointNW.longitude(), pointSE.altitude()));
69 coords.append(QGeoCoordinate(pointNW.latitude(), pointSE.longitude(), pointSE.altitude()));
70 coords.append(QGeoCoordinate(pointSE.latitude(), pointSE.longitude(), pointSE.altitude()));
71 coords.append(QGeoCoordinate(pointSE.latitude(), pointNW.longitude(), pointSE.altitude()));
72 coords.append(QGeoCoordinate(pointNW.latitude(), pointNW.longitude(), pointSE.altitude()));
73 }
74 }
75 return coords;
76}
77
78//-----------------------------------------------------------------------------
79bool
80QGCGeoBoundingCube::operator ==(const QList<QGeoCoordinate>& coords) const
81{
82 QList<QGeoCoordinate> c = polygon2D();
83 if(c.size() != coords.size()) return false;
84 for(int i = 0; i < c.size(); i++) {
85 if(c[i] != coords[i]) return false;
86 }
87 return true;
88}
89
90//-----------------------------------------------------------------------------
91double
93{
94 if(!isValid())
95 return 0.0;
96 QGeoCoordinate ne = QGeoCoordinate(pointNW.latitude(), pointSE.longitude());
97 return pointNW.distanceTo(ne);
98}
99
100//-----------------------------------------------------------------------------
101double
103{
104 if(!isValid())
105 return 0.0;
106 QGeoCoordinate sw = QGeoCoordinate(pointSE.latitude(), pointNW.longitude());
107 return pointNW.distanceTo(sw);
108}
109
110//-----------------------------------------------------------------------------
111double
113{
114 if(!isValid())
115 return 0.0;
116 // Area in km^2
117 double a = (height() / 1000.0) * (width() / 1000.0);
118 return a;
119}
120
121//-----------------------------------------------------------------------------
122double
124{
125 if(!isValid())
126 return 0.0;
127 return pointNW.distanceTo(pointSE) / 2.0;
128}
QGeoCoordinate center() const
QGCGeoBoundingCube(QObject *parent=nullptr)
QList< QGeoCoordinate > polygon2D(double clipTo=0.0) const
bool operator==(const QGCGeoBoundingCube &other) const