SMACC2
Loading...
Searching...
No Matches
cl_px4_mr::MapProjection Class Reference

#include <geo_utils.hpp>

Collaboration diagram for cl_px4_mr::MapProjection:
Collaboration graph

Public Member Functions

 MapProjection ()=default
 
 MapProjection (double lat0, double lon0, uint64_t timestamp=0)
 
void initReference (double lat0, double lon0, uint64_t timestamp=0)
 
bool isInitialized () const
 
uint64_t referenceTimestamp () const
 
double referenceLat () const
 
double referenceLon () const
 
void project (double lat, double lon, float &x, float &y) const
 
void reproject (float x, float y, double &lat, double &lon) const
 

Private Attributes

uint64_t refTimestamp_ = 0
 
double refLat_ = 0.0
 
double refLon_ = 0.0
 
double refSinLat_ = 0.0
 
double refCosLat_ = 1.0
 
bool initialized_ = false
 

Detailed Description

Definition at line 69 of file geo_utils.hpp.

Constructor & Destructor Documentation

◆ MapProjection() [1/2]

cl_px4_mr::MapProjection::MapProjection ( )
default

◆ MapProjection() [2/2]

cl_px4_mr::MapProjection::MapProjection ( double lat0,
double lon0,
uint64_t timestamp = 0 )
inline

Definition at line 74 of file geo_utils.hpp.

75 {
76 initReference(lat0, lon0, timestamp);
77 }
void initReference(double lat0, double lon0, uint64_t timestamp=0)
Definition geo_utils.hpp:79

References initReference().

Here is the call graph for this function:

Member Function Documentation

◆ initReference()

void cl_px4_mr::MapProjection::initReference ( double lat0,
double lon0,
uint64_t timestamp = 0 )
inline

Definition at line 79 of file geo_utils.hpp.

References initialized_, cl_px4_mr::geo_detail::radians(), refCosLat_, refLat_, refLon_, refSinLat_, and refTimestamp_.

Referenced by MapProjection(), and cl_px4_mr::CpVehicleLocalPosition::onPositionMessage().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isInitialized()

bool cl_px4_mr::MapProjection::isInitialized ( ) const
inline

◆ project()

void cl_px4_mr::MapProjection::project ( double lat,
double lon,
float & x,
float & y ) const
inline

Definition at line 95 of file geo_utils.hpp.

96 {
97 const double latRad = geo_detail::radians(lat);
98 const double lonRad = geo_detail::radians(lon);
99
100 const double sinLat = std::sin(latRad);
101 const double cosLat = std::cos(latRad);
102 const double cosDLon = std::cos(lonRad - refLon_);
103
104 const double arg =
105 geo_detail::constrain(refSinLat_ * sinLat + refCosLat_ * cosLat * cosDLon, -1.0, 1.0);
106 const double c = std::acos(arg);
107
108 double k = 1.0;
109 if (std::fabs(c) > 0.0)
110 {
111 k = c / std::sin(c);
112 }
113
114 x =
115 static_cast<float>(k * (refCosLat_ * sinLat - refSinLat_ * cosLat * cosDLon) * kEarthRadiusM);
116 y = static_cast<float>(k * cosLat * std::sin(lonRad - refLon_) * kEarthRadiusM);
117 }
double constrain(double v, double lo, double hi)
Definition geo_utils.hpp:65
constexpr double kEarthRadiusM
Definition geo_utils.hpp:59

References cl_px4_mr::geo_detail::constrain(), cl_px4_mr::kEarthRadiusM, cl_px4_mr::geo_detail::radians(), refCosLat_, refLon_, and refSinLat_.

Referenced by cl_px4_mr::CpVehicleLocalPosition::projectToNed().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ referenceLat()

double cl_px4_mr::MapProjection::referenceLat ( ) const
inline

Definition at line 91 of file geo_utils.hpp.

double degrees(double rad)
Definition geo_utils.hpp:64

References cl_px4_mr::geo_detail::degrees(), and refLat_.

Here is the call graph for this function:

◆ referenceLon()

double cl_px4_mr::MapProjection::referenceLon ( ) const
inline

Definition at line 92 of file geo_utils.hpp.

References cl_px4_mr::geo_detail::degrees(), and refLon_.

Here is the call graph for this function:

◆ referenceTimestamp()

uint64_t cl_px4_mr::MapProjection::referenceTimestamp ( ) const
inline

Definition at line 90 of file geo_utils.hpp.

90{ return refTimestamp_; }

References refTimestamp_.

◆ reproject()

void cl_px4_mr::MapProjection::reproject ( float x,
float y,
double & lat,
double & lon ) const
inline

Definition at line 120 of file geo_utils.hpp.

121 {
122 const double xRad = static_cast<double>(x) / kEarthRadiusM;
123 const double yRad = static_cast<double>(y) / kEarthRadiusM;
124 const double c = std::sqrt(xRad * xRad + yRad * yRad);
125
126 if (std::fabs(c) > 0.0)
127 {
128 const double sinC = std::sin(c);
129 const double cosC = std::cos(c);
130
131 const double latRad = std::asin(cosC * refSinLat_ + (xRad * sinC * refCosLat_) / c);
132 const double lonRad =
133 refLon_ + std::atan2(yRad * sinC, c * refCosLat_ * cosC - xRad * refSinLat_ * sinC);
134
135 lat = geo_detail::degrees(latRad);
136 lon = geo_detail::degrees(lonRad);
137 }
138 else
139 {
142 }
143 }

References cl_px4_mr::geo_detail::degrees(), cl_px4_mr::kEarthRadiusM, refCosLat_, refLat_, refLon_, and refSinLat_.

Referenced by cl_px4_mr::CpVehicleLocalPosition::reprojectFromNed().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ initialized_

bool cl_px4_mr::MapProjection::initialized_ = false
private

Definition at line 151 of file geo_utils.hpp.

Referenced by initReference(), and isInitialized().

◆ refCosLat_

double cl_px4_mr::MapProjection::refCosLat_ = 1.0
private

Definition at line 150 of file geo_utils.hpp.

Referenced by initReference(), project(), and reproject().

◆ refLat_

double cl_px4_mr::MapProjection::refLat_ = 0.0
private

Definition at line 147 of file geo_utils.hpp.

Referenced by initReference(), referenceLat(), and reproject().

◆ refLon_

double cl_px4_mr::MapProjection::refLon_ = 0.0
private

Definition at line 148 of file geo_utils.hpp.

Referenced by initReference(), project(), referenceLon(), and reproject().

◆ refSinLat_

double cl_px4_mr::MapProjection::refSinLat_ = 0.0
private

Definition at line 149 of file geo_utils.hpp.

Referenced by initReference(), project(), and reproject().

◆ refTimestamp_

uint64_t cl_px4_mr::MapProjection::refTimestamp_ = 0
private

Definition at line 146 of file geo_utils.hpp.

Referenced by initReference(), and referenceTimestamp().


The documentation for this class was generated from the following file: