27 changed files with 297 additions and 132 deletions
@ -0,0 +1,83 @@
@@ -0,0 +1,83 @@
|
||||
/****************************************************************************
|
||||
* |
||||
* (c) 2009-2016 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
|
||||
* |
||||
* QGroundControl is licensed according to the terms in the file |
||||
* COPYING.md in the root of the source code directory. |
||||
* |
||||
****************************************************************************/ |
||||
|
||||
#include "QGCGeoBoundingCube.h" |
||||
#include <QDebug> |
||||
|
||||
double QGCGeoBoundingCube::MaxAlt = 1000000.0; |
||||
double QGCGeoBoundingCube::MinAlt = -1000000.0; |
||||
double QGCGeoBoundingCube::MaxNorth = 90.0; |
||||
double QGCGeoBoundingCube::MaxSouth = -90.0; |
||||
double QGCGeoBoundingCube::MaxWest = -180.0; |
||||
double QGCGeoBoundingCube::MaxEast = 180.0; |
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
bool |
||||
QGCGeoBoundingCube::isValid() const |
||||
{ |
||||
return pointNW.isValid() && pointSE.isValid() && pointNW.latitude() != MaxSouth && pointSE.latitude() != MaxNorth && \
|
||||
pointNW.longitude() != MaxEast && pointSE.longitude() != MaxWest && pointNW.altitude() < MaxAlt and pointSE.altitude() > MinAlt; |
||||
} |
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
QGeoCoordinate |
||||
QGCGeoBoundingCube::center() const |
||||
{ |
||||
double lat = (((pointNW.latitude() + 90.0) + (pointSE.latitude() + 90.0)) / 2.0) - 90.0; |
||||
double lon = (((pointNW.longitude() + 180.0) + (pointSE.longitude() + 180.0)) / 2.0) - 180.0; |
||||
double alt = (pointNW.altitude() + pointSE.altitude()) / 2.0; |
||||
//qDebug() << pointNW << pointSE << QGeoCoordinate(lat, lon, alt);
|
||||
return QGeoCoordinate(lat, lon, alt); |
||||
} |
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
QList<QGeoCoordinate> |
||||
QGCGeoBoundingCube::polygon2D() const |
||||
{ |
||||
QList<QGeoCoordinate> coords; |
||||
coords.append(QGeoCoordinate(pointNW.latitude(), pointNW.longitude(), pointSE.altitude())); |
||||
coords.append(QGeoCoordinate(pointNW.latitude(), pointSE.longitude(), pointSE.altitude())); |
||||
coords.append(QGeoCoordinate(pointSE.latitude(), pointSE.longitude(), pointSE.altitude())); |
||||
coords.append(QGeoCoordinate(pointSE.latitude(), pointNW.longitude(), pointSE.altitude())); |
||||
coords.append(QGeoCoordinate(pointNW.latitude(), pointNW.longitude(), pointSE.altitude())); |
||||
return coords; |
||||
} |
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
double |
||||
QGCGeoBoundingCube::width() const |
||||
{ |
||||
QGeoCoordinate ne = QGeoCoordinate(pointNW.latitude(), pointSE.longitude()); |
||||
return pointNW.distanceTo(ne); |
||||
} |
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
double |
||||
QGCGeoBoundingCube::height() const |
||||
{ |
||||
QGeoCoordinate sw = QGeoCoordinate(pointSE.latitude(), pointNW.longitude()); |
||||
return pointNW.distanceTo(sw); |
||||
} |
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
double |
||||
QGCGeoBoundingCube::area() const |
||||
{ |
||||
// Area in km^2
|
||||
double a = (height() / 1000.0) * (width() / 1000.0); |
||||
//qDebug() << "Area:" << a;
|
||||
return a; |
||||
} |
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
double |
||||
QGCGeoBoundingCube::radius() const |
||||
{ |
||||
return pointNW.distanceTo(pointSE) / 2.0; |
||||
} |
@ -0,0 +1,77 @@
@@ -0,0 +1,77 @@
|
||||
/****************************************************************************
|
||||
* |
||||
* (c) 2009-2016 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
|
||||
* |
||||
* QGroundControl is licensed according to the terms in the file |
||||
* COPYING.md in the root of the source code directory. |
||||
* |
||||
****************************************************************************/ |
||||
|
||||
|
||||
#pragma once |
||||
|
||||
#include <QObject> |
||||
#include <QGeoCoordinate> |
||||
|
||||
// A bounding "cube" for small surface areas (doesn't take in consideration earth's curvature)
|
||||
// Coordinate system makes NW Up Left Bottom (0,0,0) and SE Bottom Right Top (y,x,z)
|
||||
class QGCGeoBoundingCube : public QObject { |
||||
Q_OBJECT |
||||
public: |
||||
QGCGeoBoundingCube(const QGCGeoBoundingCube& other) |
||||
{ |
||||
pointNW = other.pointNW; |
||||
pointSE = other.pointSE; |
||||
} |
||||
|
||||
QGCGeoBoundingCube() |
||||
: pointNW(QGeoCoordinate(MaxSouth, MaxEast, MaxAlt)) |
||||
, pointSE(QGeoCoordinate(MaxNorth, MaxWest, MinAlt)) |
||||
{ |
||||
} |
||||
|
||||
QGCGeoBoundingCube(QGeoCoordinate p1, QGeoCoordinate p2) |
||||
: pointNW(p1) |
||||
, pointSE(p2) |
||||
{ |
||||
} |
||||
|
||||
Q_PROPERTY(QGeoCoordinate pointNW MEMBER pointNW CONSTANT) |
||||
Q_PROPERTY(QGeoCoordinate pointSE MEMBER pointNW CONSTANT) |
||||
|
||||
Q_INVOKABLE bool isValid() const; |
||||
Q_INVOKABLE QGeoCoordinate center() const; |
||||
|
||||
inline bool operator ==(const QGCGeoBoundingCube& other) |
||||
{ |
||||
return pointNW == other.pointNW && pointSE == other.pointSE; |
||||
} |
||||
|
||||
inline bool operator !=(const QGCGeoBoundingCube& other) |
||||
{ |
||||
return !(*this == other); |
||||
} |
||||
|
||||
inline const QGCGeoBoundingCube& operator =(const QGCGeoBoundingCube& other) |
||||
{ |
||||
pointNW = other.pointNW; |
||||
pointSE = other.pointSE; |
||||
return *this; |
||||
} |
||||
|
||||
//-- 2D
|
||||
QList<QGeoCoordinate> polygon2D() const; |
||||
double width () const; |
||||
double height () const; |
||||
double area () const; |
||||
double radius () const; |
||||
|
||||
QGeoCoordinate pointNW; |
||||
QGeoCoordinate pointSE; |
||||
static double MaxAlt; |
||||
static double MinAlt; |
||||
static double MaxNorth; |
||||
static double MaxSouth; |
||||
static double MaxWest; |
||||
static double MaxEast; |
||||
}; |
Loading…
Reference in new issue