【问题标题】:define a boost::units angle in degrees以度为单位定义一个 boost::units 角度
【发布时间】:2021-06-03 13:37:57
【问题描述】:

如何以度为单位定义增强单位角度?下面显示了有效的弧度和无效的度数。

#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);

【问题讨论】:

    标签: c++ boost-units


    【解决方案1】:

    使用boost::units::degree::degree:

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

    两行

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

    成为boost::units::degree命名空间中的这两个静态常量:

    static const plane_angle degree;
    static const plane_angle degrees;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-13
      • 1970-01-01
      • 1970-01-01
      • 2011-11-18
      • 2022-01-01
      相关资源
      最近更新 更多