Use boost to convert degrees minutes seconds. Radians boost_1_48_0

I have this code to work:

typedef model::point<double, 2, cs::spherical_equatorial<degree> > degree_point; degree_point FlindersSE(-37.0, 144.0); 

and this:

 quantity<plane_angle> Flinders = 0.375 * radians; //this works 0.375 radians 

But I would like to make degrees of minutes and seconds and convert to radians, and then back.

I spent the whole day trying to figure out how the enhancement system works - the examples are a bit subtle on the ground, so I was wondering if anyone could show a quick example?

Thanks in advance 8+)

Edit

 //quantity<degree_base_unit> FlindersSDeg2.value(-37.0); //quantity< angle::arcminute_base_unit> FlindersSMin = 57.0; //quantity< angle::arcsecond_base_unit> FlindersSSec = 3.72030; 

I think I need to better understand how the declaration works. :)

Edit2:

Thank you very much - maybe I spent a whole search looking for ways to do this with boost, and there was no money there! I thought it could be because I found this legacy code here http://www.boost.org/doc/libs/1_47_0/libs/geometry/doc/doxy/doxygen_input/sourcecode/doxygen_1.cpp

 void example_dms() { /* Extension, other coordinate system: // Construction with degree/minute/seconds boost::geometry::dms<boost::geometry::east> d1(4, 53, 32.5); // Explicit conversion to double. std::cout << d1.as_value() << std::endl; // Conversion to string, with optional strings std::cout << d1.get_dms(" deg ", " min ", " sec") << std::endl; // Combination with latitude/longitude and cardinal directions { using namespace boost::geometry; point_ll<double, boost::geometry::cs::geographic<boost::geometry::degree> > canberra( latitude<>(dms<south>(35, 18, 27)), longitude<>(dms<east>(149, 7, 27.9))); std::cout << canberra << std::endl; } */ } 
+4
source share
3 answers

Here are some conversion methods that I use with blocks and elevation angles:

 double ToDegrees(const Angle & angle) { return static_cast<boost::units::quantity<boost::units::degree::plane_angle>>(angle).value(); } double ToRadians(const Angle & angle) { return static_cast<boost::units::quantity<boost::units::si::plane_angle>>(angle).value(); } 

They are supplemented by types of safe plants:

 Angle Degrees(double angleInDegrees) { return angleInDegrees * boost::units::degree::degrees; } Angle Radians(double angleInRadians) { return Angle(angleInRadians * boost::units::si::radians); } 

To fix degrees, minutes, seconds, replace the degrees twice as high using the transform structure as follows:

 struct DMS { DMS(double value) { degrees = std::floor(value); double rem = (value-degrees) * 60; minutes = std::floor(rem); seconds = (rem-minutes) * 60; } operator double() const { return degrees + minutes/60 + seconds/3600; } double degrees; double minutes; double seconds; }; 
+3
source

Your safe first type factory does not return an angle.

Perhaps you can try:

 return Angle( angleInDegrees * boost::units::degree::degrees); 
0
source

and make sure you have the correct types, so the correct numerical conversion is also performed (e.g. PI / 180). Use these functions to verify:

 /// theta is radian units (si) template<class Y> bool isRad(const boost::units::quantity<si::plane_angle, Y>& theta) { return true; } /// theta in other angular units template<class System, class Y> bool isRad(const boost::units::quantity<boost::units::unit<boost::units::plane_angle_dimension, System>, Y>& theta) { return false; } 
0
source

Source: https://habr.com/ru/post/1479946/


All Articles