将 boost.units 中的单位从 Angular_velocity 转换为 Degrees_per_Second
我需要将一般的 angle_velocity 转换为度/秒。
为了说明这个问题,示例 boostUnits.cpp:
#include <boost/units/systems/si.hpp>
#include <boost/units/systems/angle/revolutions.hpp>
#include <boost/units/systems/angle/degrees.hpp>
#include <boost/units/conversion.hpp>
#include <boost/units/pow.hpp>
#include <iostream>
#include <iterator>
#include <algorithm>
int main()
{
boost::units::quantity< boost::units::si::angular_velocity> m_speed(
(30.0*boost::units::si::radians_per_second)
);
std::cout << "m_speed: " << m_speed << std::endl;
uint32_t result = static_cast<uint32_t>(
boost::units::quantity<boost::units::si::angular_velocity,uint32_t>(
m_speed*boost::units::degree::degrees/boost::units::si::seconds
).value()
);
std::cout << " result: "<< result << std::endl;
return(0);
}
产生以下编译器输出:
g++ boostUnits.cpp
/usr/local/include/boost/units/detail/conversion_impl.hpp: In static member function ‘static boost::units::quantity<Unit2, T2> boost::units::conversion_helper<boost::units::quantity<Unit1, T1>, boost::units::quantity<Unit2, T2> >::convert(const boost::units::quantity<Unit1, T1>&) [with Unit1 = boost::units::unit<boost::units::list<boost::units::dim<boost::units::time_base_dimension, boost::units::static_rational<-0x000000002l, 1l> >, boost::units::list<boost::units::dim<boost::units::plane_angle_base_dimension, boost::units::static_rational<2l, 1l> >, boost::units::dimensionless_type> >, boost::units::heterogeneous_system<boost::units::heterogeneous_system_impl<boost::units::list<boost::units::heterogeneous_system_dim<boost::units::angle::degree_base_unit, boost::units::static_rational<1l, 1l> >, boost::units::list<boost::units::heterogeneous_system_dim<boost::units::si::second_base_unit, boost::units::static_rational<-0x000000002l, 1l> >, boost::units::list<boost::units::heterogeneous_system_dim<boost::units::angle::radian_base_unit, boost::units::static_rational<1l, 1l> >, boost::units::dimensionless_type> > >, boost::units::list<boost::units::dim<boost::units::time_base_dimension, boost::units::static_rational<-0x000000002l, 1l> >, boost::units::list<boost::units::dim<boost::units::plane_angle_base_dimension, boost::units::static_rational<2l, 1l> >, boost::units::dimensionless_type> >, boost::units::dimensionless_type> >, void>, T1 = double, Unit2 = boost::units::unit<boost::units::list<boost::units::dim<boost::units::time_base_dimension, boost::units::static_rational<-0x000000001l, 1l> >, boost::units::list<boost::units::dim<boost::units::plane_angle_base_dimension, boost::units::static_rational<1l, 1l> >, boost::units::dimensionless_type> >, boost::units::homogeneous_system<boost::units::list<boost::units::si::meter_base_unit, boost::units::list<boost::units::scaled_base_unit<boost::units::cgs::gram_base_unit, boost::units::scale<10l, boost::units::static_rational<3l, 1l> > >, boost::units::list<boost::units::si::second_base_unit, boost::units::list<boost::units::si::ampere_base_unit, boost::units::list<boost::units::si::kelvin_base_unit, boost::units::list<boost::units::si::mole_base_unit, boost::units::list<boost::units::si::candela_base_unit, boost::units::list<boost::units::angle::radian_base_unit, boost::units::list<boost::units::angle::steradian_base_unit, boost::units::dimensionless_type> > > > > > > > > >, void>, T2 = unsigned int]’:
/usr/local/include/boost/units/quantity.hpp:193: instantiated from ‘boost::units::quantity<Unit, Y>::quantity(const boost::units::quantity<Unit2, YY>&, typename boost::disable_if<boost::mpl::and_<typename boost::units::is_implicitly_convertible<Unit2, Unit>::type, boost::units::detail::is_non_narrowing_conversion<YY, Y>, mpl_::bool_<true>, mpl_::bool_<true>, mpl_::bool_<true> >, typename boost::units::detail::disable_if_is_same<Unit, Unit2>::type>::type*) [with Unit2 = boost::units::unit<boost::units::list<boost::units::dim<boost::units::time_base_dimension, boost::units::static_rational<-0x000000002l, 1l> >, boost::units::list<boost::units::dim<boost::units::plane_angle_base_dimension, boost::units::static_rational<2l, 1l> >, boost::units::dimensionless_type> >, boost::units::heterogeneous_system<boost::units::heterogeneous_system_impl<boost::units::list<boost::units::heterogeneous_system_dim<boost::units::angle::degree_base_unit, boost::units::static_rational<1l, 1l> >, boost::units::list<boost::units::heterogeneous_system_dim<boost::units::si::second_base_unit, boost::units::static_rational<-0x000000002l, 1l> >, boost::units::list<boost::units::heterogeneous_system_dim<boost::units::angle::radian_base_unit, boost::units::static_rational<1l, 1l> >, boost::units::dimensionless_type> > >, boost::units::list<boost::units::dim<boost::units::time_base_dimension, boost::units::static_rational<-0x000000002l, 1l> >, boost::units::list<boost::units::dim<boost::units::plane_angle_base_dimension, boost::units::static_rational<2l, 1l> >, boost::units::dimensionless_type> >, boost::units::dimensionless_type> >, void>, YY = double, Unit = boost::units::unit<boost::units::list<boost::units::dim<boost::units::time_base_dimension, boost::units::static_rational<-0x000000001l, 1l> >, boost::units::list<boost::units::dim<boost::units::plane_angle_base_dimension, boost::units::static_rational<1l, 1l> >, boost::units::dimensionless_type> >, boost::units::homogeneous_system<boost::units::list<boost::units::si::meter_base_unit, boost::units::list<boost::units::scaled_base_unit<boost::units::cgs::gram_base_unit, boost::units::scale<10l, boost::units::static_rational<3l, 1l> > >, boost::units::list<boost::units::si::second_base_unit, boost::units::list<boost::units::si::ampere_base_unit, boost::units::list<boost::units::si::kelvin_base_unit, boost::units::list<boost::units::si::mole_base_unit, boost::units::list<boost::units::si::candela_base_unit, boost::units::list<boost::units::angle::radian_base_unit, boost::units::list<boost::units::angle::steradian_base_unit, boost::units::dimensionless_type> > > > > > > > > >, void>, Y = unsigned int]’
boostUnits.cpp:16: instantiated from here
/usr/local/include/boost/units/detail/conversion_impl.hpp:345: error: no matching function for call to ‘conversion_factor(boost::units::unit<boost::units::list<boost::units::dim<boost::units::time_base_dimension, boost::units::static_rational<-0x000000002l, 1l> >, boost::units::list<boost::units::dim<boost::units::plane_angle_base_dimension, boost::units::static_rational<2l, 1l> >, boost::units::dimensionless_type> >, boost::units::heterogeneous_system<boost::units::heterogeneous_system_impl<boost::units::list<boost::units::heterogeneous_system_dim<boost::units::angle::degree_base_unit, boost::units::static_rational<1l, 1l> >, boost::units::list<boost::units::heterogeneous_system_dim<boost::units::si::second_base_unit, boost::units::static_rational<-0x000000002l, 1l> >, boost::units::list<boost::units::heterogeneous_system_dim<boost::units::angle::radian_base_unit, boost::units::static_rational<1l, 1l> >, boost::units::dimensionless_type> > >, boost::units::list<boost::units::dim<boost::units::time_base_dimension, boost::units::static_rational<-0x000000002l, 1l> >, boost::units::list<boost::units::dim<boost::units::plane_angle_base_dimension, boost::units::static_rational<2l, 1l> >, boost::units::dimensionless_type> >, boost::units::dimensionless_type> >, void>&, boost::units::unit<boost::units::list<boost::units::dim<boost::units::time_base_dimension, boost::units::static_rational<-0x000000001l, 1l> >, boost::units::list<boost::units::dim<boost::units::plane_angle_base_dimension, boost::units::static_rational<1l, 1l> >, boost::units::dimensionless_type> >, boost::units::homogeneous_system<boost::units::list<boost::units::si::meter_base_unit, boost::units::list<boost::units::scaled_base_unit<boost::units::cgs::gram_base_unit, boost::units::scale<10l, boost::units::static_rational<3l, 1l> > >, boost::units::list<boost::units::si::second_base_unit, boost::units::list<boost::units::si::ampere_base_unit, boost::units::list<boost::units::si::kelvin_base_unit, boost::units::list<boost::units::si::mole_base_unit, boost::units::list<boost::units::si::candela_base_unit, boost::units::list<boost::units::angle::radian_base_unit, boost::units::list<boost::units::angle::steradian_base_unit, boost::units::dimensionless_type> > > > > > > > > >, void>&)’
实现所需类型规范和后续转换的语法是什么? 我是否需要指定 Degrees_per_Second 单位?如果需要,如何指定?
文档: http://www.boost.org/doc/ libs/1_37_0/doc/html/boost_units.html
预先感谢您的帮助。
I need to make a conversion from a general angular_velocity to degrees/second.
To illustrate this problem the example boostUnits.cpp:
#include <boost/units/systems/si.hpp>
#include <boost/units/systems/angle/revolutions.hpp>
#include <boost/units/systems/angle/degrees.hpp>
#include <boost/units/conversion.hpp>
#include <boost/units/pow.hpp>
#include <iostream>
#include <iterator>
#include <algorithm>
int main()
{
boost::units::quantity< boost::units::si::angular_velocity> m_speed(
(30.0*boost::units::si::radians_per_second)
);
std::cout << "m_speed: " << m_speed << std::endl;
uint32_t result = static_cast<uint32_t>(
boost::units::quantity<boost::units::si::angular_velocity,uint32_t>(
m_speed*boost::units::degree::degrees/boost::units::si::seconds
).value()
);
std::cout << " result: "<< result << std::endl;
return(0);
}
Produces this compiler output:
g++ boostUnits.cpp
/usr/local/include/boost/units/detail/conversion_impl.hpp: In static member function ‘static boost::units::quantity<Unit2, T2> boost::units::conversion_helper<boost::units::quantity<Unit1, T1>, boost::units::quantity<Unit2, T2> >::convert(const boost::units::quantity<Unit1, T1>&) [with Unit1 = boost::units::unit<boost::units::list<boost::units::dim<boost::units::time_base_dimension, boost::units::static_rational<-0x000000002l, 1l> >, boost::units::list<boost::units::dim<boost::units::plane_angle_base_dimension, boost::units::static_rational<2l, 1l> >, boost::units::dimensionless_type> >, boost::units::heterogeneous_system<boost::units::heterogeneous_system_impl<boost::units::list<boost::units::heterogeneous_system_dim<boost::units::angle::degree_base_unit, boost::units::static_rational<1l, 1l> >, boost::units::list<boost::units::heterogeneous_system_dim<boost::units::si::second_base_unit, boost::units::static_rational<-0x000000002l, 1l> >, boost::units::list<boost::units::heterogeneous_system_dim<boost::units::angle::radian_base_unit, boost::units::static_rational<1l, 1l> >, boost::units::dimensionless_type> > >, boost::units::list<boost::units::dim<boost::units::time_base_dimension, boost::units::static_rational<-0x000000002l, 1l> >, boost::units::list<boost::units::dim<boost::units::plane_angle_base_dimension, boost::units::static_rational<2l, 1l> >, boost::units::dimensionless_type> >, boost::units::dimensionless_type> >, void>, T1 = double, Unit2 = boost::units::unit<boost::units::list<boost::units::dim<boost::units::time_base_dimension, boost::units::static_rational<-0x000000001l, 1l> >, boost::units::list<boost::units::dim<boost::units::plane_angle_base_dimension, boost::units::static_rational<1l, 1l> >, boost::units::dimensionless_type> >, boost::units::homogeneous_system<boost::units::list<boost::units::si::meter_base_unit, boost::units::list<boost::units::scaled_base_unit<boost::units::cgs::gram_base_unit, boost::units::scale<10l, boost::units::static_rational<3l, 1l> > >, boost::units::list<boost::units::si::second_base_unit, boost::units::list<boost::units::si::ampere_base_unit, boost::units::list<boost::units::si::kelvin_base_unit, boost::units::list<boost::units::si::mole_base_unit, boost::units::list<boost::units::si::candela_base_unit, boost::units::list<boost::units::angle::radian_base_unit, boost::units::list<boost::units::angle::steradian_base_unit, boost::units::dimensionless_type> > > > > > > > > >, void>, T2 = unsigned int]’:
/usr/local/include/boost/units/quantity.hpp:193: instantiated from ‘boost::units::quantity<Unit, Y>::quantity(const boost::units::quantity<Unit2, YY>&, typename boost::disable_if<boost::mpl::and_<typename boost::units::is_implicitly_convertible<Unit2, Unit>::type, boost::units::detail::is_non_narrowing_conversion<YY, Y>, mpl_::bool_<true>, mpl_::bool_<true>, mpl_::bool_<true> >, typename boost::units::detail::disable_if_is_same<Unit, Unit2>::type>::type*) [with Unit2 = boost::units::unit<boost::units::list<boost::units::dim<boost::units::time_base_dimension, boost::units::static_rational<-0x000000002l, 1l> >, boost::units::list<boost::units::dim<boost::units::plane_angle_base_dimension, boost::units::static_rational<2l, 1l> >, boost::units::dimensionless_type> >, boost::units::heterogeneous_system<boost::units::heterogeneous_system_impl<boost::units::list<boost::units::heterogeneous_system_dim<boost::units::angle::degree_base_unit, boost::units::static_rational<1l, 1l> >, boost::units::list<boost::units::heterogeneous_system_dim<boost::units::si::second_base_unit, boost::units::static_rational<-0x000000002l, 1l> >, boost::units::list<boost::units::heterogeneous_system_dim<boost::units::angle::radian_base_unit, boost::units::static_rational<1l, 1l> >, boost::units::dimensionless_type> > >, boost::units::list<boost::units::dim<boost::units::time_base_dimension, boost::units::static_rational<-0x000000002l, 1l> >, boost::units::list<boost::units::dim<boost::units::plane_angle_base_dimension, boost::units::static_rational<2l, 1l> >, boost::units::dimensionless_type> >, boost::units::dimensionless_type> >, void>, YY = double, Unit = boost::units::unit<boost::units::list<boost::units::dim<boost::units::time_base_dimension, boost::units::static_rational<-0x000000001l, 1l> >, boost::units::list<boost::units::dim<boost::units::plane_angle_base_dimension, boost::units::static_rational<1l, 1l> >, boost::units::dimensionless_type> >, boost::units::homogeneous_system<boost::units::list<boost::units::si::meter_base_unit, boost::units::list<boost::units::scaled_base_unit<boost::units::cgs::gram_base_unit, boost::units::scale<10l, boost::units::static_rational<3l, 1l> > >, boost::units::list<boost::units::si::second_base_unit, boost::units::list<boost::units::si::ampere_base_unit, boost::units::list<boost::units::si::kelvin_base_unit, boost::units::list<boost::units::si::mole_base_unit, boost::units::list<boost::units::si::candela_base_unit, boost::units::list<boost::units::angle::radian_base_unit, boost::units::list<boost::units::angle::steradian_base_unit, boost::units::dimensionless_type> > > > > > > > > >, void>, Y = unsigned int]’
boostUnits.cpp:16: instantiated from here
/usr/local/include/boost/units/detail/conversion_impl.hpp:345: error: no matching function for call to ‘conversion_factor(boost::units::unit<boost::units::list<boost::units::dim<boost::units::time_base_dimension, boost::units::static_rational<-0x000000002l, 1l> >, boost::units::list<boost::units::dim<boost::units::plane_angle_base_dimension, boost::units::static_rational<2l, 1l> >, boost::units::dimensionless_type> >, boost::units::heterogeneous_system<boost::units::heterogeneous_system_impl<boost::units::list<boost::units::heterogeneous_system_dim<boost::units::angle::degree_base_unit, boost::units::static_rational<1l, 1l> >, boost::units::list<boost::units::heterogeneous_system_dim<boost::units::si::second_base_unit, boost::units::static_rational<-0x000000002l, 1l> >, boost::units::list<boost::units::heterogeneous_system_dim<boost::units::angle::radian_base_unit, boost::units::static_rational<1l, 1l> >, boost::units::dimensionless_type> > >, boost::units::list<boost::units::dim<boost::units::time_base_dimension, boost::units::static_rational<-0x000000002l, 1l> >, boost::units::list<boost::units::dim<boost::units::plane_angle_base_dimension, boost::units::static_rational<2l, 1l> >, boost::units::dimensionless_type> >, boost::units::dimensionless_type> >, void>&, boost::units::unit<boost::units::list<boost::units::dim<boost::units::time_base_dimension, boost::units::static_rational<-0x000000001l, 1l> >, boost::units::list<boost::units::dim<boost::units::plane_angle_base_dimension, boost::units::static_rational<1l, 1l> >, boost::units::dimensionless_type> >, boost::units::homogeneous_system<boost::units::list<boost::units::si::meter_base_unit, boost::units::list<boost::units::scaled_base_unit<boost::units::cgs::gram_base_unit, boost::units::scale<10l, boost::units::static_rational<3l, 1l> > >, boost::units::list<boost::units::si::second_base_unit, boost::units::list<boost::units::si::ampere_base_unit, boost::units::list<boost::units::si::kelvin_base_unit, boost::units::list<boost::units::si::mole_base_unit, boost::units::list<boost::units::si::candela_base_unit, boost::units::list<boost::units::angle::radian_base_unit, boost::units::list<boost::units::angle::steradian_base_unit, boost::units::dimensionless_type> > > > > > > > > >, void>&)’
What is the syntax to achieve the desired type specification and subsequent conversion?
Do I need to specify a degrees_per_second unit, and if so, how?
Documentation: http://www.boost.org/doc/libs/1_37_0/doc/html/boost_units.html
Thank you in advance for your help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Steven Wantabe 在 boost-users 邮件列表上提供了解决方案。
我在下面实现了一个工作示例。
boostUnits.cpp:
终端输出:
Steven Wantabe provided the solution on the boost-users mailing list.
I implemented a working example below.
boostUnits.cpp:
Terminal Output:
你不需要那么多代码。自然代数可以帮助你实现这一目标。
输出:
You don't need that much code. Natural algebra can get you there.
Output: