started adding earth-mapping
some new helper methods added support for floorplan metadata load/save
This commit is contained in:
75
geo/EarthMapping.h
Normal file
75
geo/EarthMapping.h
Normal file
@@ -0,0 +1,75 @@
|
||||
#ifndef EARTHMAPPING_H
|
||||
#define EARTHMAPPING_H
|
||||
|
||||
#include "Point3.h"
|
||||
#include "EarthPos.h"
|
||||
|
||||
/**
|
||||
* mapping between positions on earth and positions within the floorplan
|
||||
*/
|
||||
class EarthMapping {
|
||||
|
||||
private:
|
||||
|
||||
/** one 3D position within the floorplan */
|
||||
Point3 center_map_m;
|
||||
|
||||
/** corresponding 3D position on earth */
|
||||
EarthPos center_earth;
|
||||
|
||||
/** rotation [in degrees] to ensure that the map's y-up-axis points towards the north */
|
||||
float rotation_deg;
|
||||
|
||||
double m_per_deg_lat;
|
||||
double m_per_deg_lon;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
void build() {
|
||||
|
||||
// TODO
|
||||
|
||||
}
|
||||
|
||||
/** convert from map-coordinates to earth-coordinates */
|
||||
EarthPos mapToWorld(const Point3 mapPos_m) const {
|
||||
|
||||
Point3 pos = mapPos_m;
|
||||
|
||||
// move to (0,0,0)
|
||||
pos -= center_map_m;
|
||||
|
||||
// undo the rotation
|
||||
const Point2 xy = pos.xy().rotated(-rotation_deg / 180.0 * (float) M_PI);
|
||||
|
||||
// convert this "delta to (0,0,0)" to lon/lat and move it to the lon/lat-center
|
||||
const double lat = cenLat + (xy.y / m_per_deg_lat);
|
||||
const double lon = cenLon + (xy.x / m_per_deg_lon);
|
||||
const float height = pos.z;
|
||||
|
||||
// done
|
||||
return EarthPos(lat, lon, height);
|
||||
|
||||
}
|
||||
|
||||
/** convert from earth-coordinates to map-coordinates */
|
||||
Point3 worldToMap(const EarthPos earthPos) const {
|
||||
|
||||
const double y_m = +(lat-cenLat) * m_per_deg_lat;
|
||||
const double x_m = +(lon-cenLon) * m_per_deg_lon;
|
||||
|
||||
// rotate (our map is axis aligned)
|
||||
Point2 pos(x_m, y_m);
|
||||
pos = pos.rotated(rotDeg / 180 * M_PI);
|
||||
|
||||
// apply movement
|
||||
pos += mapCenter_m;
|
||||
|
||||
return pos;
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif // EARTHMAPPING_H
|
||||
21
geo/EarthPos.h
Normal file
21
geo/EarthPos.h
Normal file
@@ -0,0 +1,21 @@
|
||||
#ifndef EARTHPOS_H
|
||||
#define EARTHPOS_H
|
||||
|
||||
/** describes the location on the earth's surface */
|
||||
struct EarthPos {
|
||||
|
||||
double lat;
|
||||
|
||||
double lon;
|
||||
|
||||
/** height above sea level */
|
||||
float height;
|
||||
|
||||
/** ctor with values */
|
||||
EarthPos(const double lat, const double lon, const float height) : lon(lon), lat(lat), height(height) {
|
||||
;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif // EARTHPOS_H
|
||||
@@ -17,6 +17,8 @@ struct Point2 {
|
||||
/** ctor */
|
||||
Point2(const float x, const float y) : x(x), y(y) {;}
|
||||
|
||||
Point2 operator - () const {return Point2(-x, -y);}
|
||||
|
||||
|
||||
Point2 operator + (const Point2& o) const {return Point2(x+o.x, y+o.y);}
|
||||
|
||||
@@ -60,4 +62,9 @@ struct Point2 {
|
||||
|
||||
};
|
||||
|
||||
inline void swap(Point2& p1, Point2& p2) {
|
||||
std::swap(p1.x, p2.x);
|
||||
std::swap(p1.y, p2.y);
|
||||
}
|
||||
|
||||
#endif // POINT2_H
|
||||
|
||||
Reference in New Issue
Block a user