|
Boost Users : |
Subject: Re: [Boost-users] boost::units - converting from one derived_dimension to another across systems (imperial to metric)
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2018-11-20 05:06:17
AMDG
On 11/19/2018 09:09 PM, Matt Vinson via Boost-users wrote:
> Eisuke Kawashima: Thank You. I'll have a look. When I saw Boost.Units did not have imperial and we had to create it ourselves, I thought: the US is s 5 trillion dollar market, most of those markets need programming, all are on imperial. Boost.Units needs imperial and programmers would find and use it.
>
> Steven Watanabe:Â Thank You.Â
> This solution doesn't seem correct as it does not consider "length"....
How is it wrong? length cancels out. The divides version
will give exactly the same type.
> boost::units::derived_dimension<
> Â boost::units::mass_base_dimension, 1,
> Â boost::units::time_base_dimension, -2>::typeI thought I'd at it (L M T^-2 L-1) but this didn't do well.:Â Â Â Â Â Â typedef boost::units::derived_dimension<
> Â Â Â Â Â Â Â Â Â boost::units::length_base_dimension, 1,
> Â Â Â Â Â Â Â Â Â boost::units::mass_base_dimension, 1,
> Â Â Â Â Â Â Â Â Â boost::units::time_base_dimension, -2,
> Â Â Â Â Â Â Â Â Â boost::units::length_base_dimension, -1
> Â Â Â Â Â Â >::type
> Â Â Â Â Â Â Â Â Â lineal_force_dimension;
>
derived_dimension can't handle multiple uses of the
same base dimension. Even if it did, it would just
cancel them out, so this serves to purpose.
> So, I tried the " typedef boost::mpl::divides<...>" solution as it has force and length. I am closer, I hope.
> *.h------------------------------------------------------------------------------------------------------------------------------------------
> namespace dimensional_analysis {
> Â Â Â Â typedef boost::units::length_base_dimension::dimension_type length_dimension;
> Â Â Â Â typedef boost::units::mass_base_dimension::dimension_type mass_dimension;
>
> Â Â Â Â typedef boost::units::make_system<
> Â Â Â Â Â Â Â Â Â boost::units::us::inch_base_unit,
> Â Â Â Â Â Â Â Â Â boost::units::us::pound_base_unit
> Â Â Â Â Â Â >::type ip_system;
>
> Â Â Â namespace lineal_force {
> Â Â Â Â Â Â typedef boost::mpl::divides<
> Â Â Â Â Â Â Â Â Â boost::units::force_dimension,
> Â Â Â Â Â Â Â Â Â boost::units::length_dimension>::type
> Â Â Â Â Â Â Â Â Â lineal_force_dimension;
> Â Â Â Â Â Â namespace imperial {
> Â Â Â Â Â Â Â Â Â typedef boost::units::unit<
> Â Â Â Â Â Â Â Â Â Â Â Â lineal_force_dimension,
> Â Â Â Â Â Â Â Â Â Â Â Â dimensional_analysis ::ip_system
> Â Â Â Â Â Â Â Â Â > lineal_force_unit;
> Â Â Â Â Â Â Â Â Â typedef boost::units::quantity<lineal_force_unit, double> pound_per_in_quantity;
> Â Â Â Â Â Â Â Â Â BOOST_UNITS_STATIC_CONSTANT(pound_per_inch, pound_per_in_quantity);
> Â Â Â Â Â Â }
> Â Â Â Â Â Â namespace si {
> Â Â Â Â Â Â Â Â Â typedef boost::units::unit<
> Â Â Â Â Â Â Â Â Â Â Â Â lineal_force_dimension,
> Â Â Â Â Â Â Â Â Â Â Â Â boost::units::si::system
> Â Â Â Â Â Â Â Â Â > lineal_force_unit;
This is not the unit you want. The SI
unit of force is N, not kg. kilogram-force
is not currently provided by Boost.Units
and you'll need to define it yourself.
(As in your previous post.)
> Â Â Â Â Â Â Â Â Â typedef boost::units::quantity<lineal_force_dimension, double> kg_per_meter_quantity;
> Â Â Â Â Â Â Â Â Â BOOST_UNITS_STATIC_CONSTANT(kg_per_meter, kg_per_meter_quantity);
> Â Â Â Â Â Â }
> Â Â Â }//lineal_force
> }//dimensional_analysis
> <snip>
In Christ,
Steven Watanabe
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net