define a boost::units angle in degrees

585 views Asked by At

How do I define a boost units angle in degrees? The below shows radian which works and degrees which does not.

#include <boost/units/unit.hpp>
#include <boost/units/systems/si/io.hpp>
#include <boost/units/systems/angle/degrees.hpp>

// This works for defining an angle in radians
boost::units::quantity<
    boost::units::unit<
        boost::units::plane_angle_dimension,
        boost::units::si::system
    >
> my_angle_radians(2.0 * boost::units::si::radian);

// This is what I'm trying to do that doesn't work
boost::units::quantity<
    boost::units::unit<
        boost::units::plane_angle_dimension,
        boost::units::degree::system
    >
> my_angle_degree(2.0 * boost::units::angle::degree_base_unit);
1

There are 1 answers

0
Ted Lyngmo On BEST ANSWER

Use boost::units::degree::degree:

my_angle_degree(2.0 * boost::units::degree::degree);

The two lines

BOOST_UNITS_STATIC_CONSTANT(degree,plane_angle);
BOOST_UNITS_STATIC_CONSTANT(degrees,plane_angle);

becomes these two static constants in the boost::units::degree namespace:

static const plane_angle degree;
static const plane_angle degrees;