Boost logo

Boost :

From: Walter Landry (wlandry_at_[hidden])
Date: 2003-12-10 17:59:38


Matthias Schabel <boost_at_[hidden]> wrote:
> >>> Two questions:
> >>> 1) What about something like Radians? I.e.: not strictly a physical
> >>> dimension, yet which under normal circumstances should not be used
> >>> like
> >>> x = 5 radians;
> >>> y = sin(x) + x; //>:-0
> >
> > Maybe it is just me, but radians and steradians are really just
> > numbers. The example above is a completely reasonable thing to do.
> > The equation (y=sin(x) + x ) is a textbook example for minimization
> > problems
>
> I guess I'd consider them to be dimensionless quantities, which are a
> slightly
> different animal - they are actually dimensionless ratios of
> length/length and
> area/area, respectively. You're completely right that the example
> equation Dan
> came up is well posed, but I can envision wanting to be able to track
> angular
> units in trig/inverse trig functions (as well as other places - :
>
> template<class Y,
> class Model>
> DimensionedQuantity<Y,DimensionedUnit<Model,dimensionless_type> >
> sin(const DimensionedQuantity<Y,DimensionedUnit<Model,angle_type> >&
> theta)
> {
> return
> std::sin(DimensionedQuantity<Y,DimensionedUnit<SIModel,angle_type>
> >(theta).value());
> }
>
> template<class Y,
> class Model>
> DimensionedQuantity<Y,DimensionedUnit<Model,angle_type> >
> asin(const
> DimensionedQuantity<Y,DimensionedUnit<Model,dimensionless_type> >& val)
> {
> const DimensionedQuantity<Y,DimensionedUnit<SIModel,angle_type> >
> ret(std::asin(val.value()));
>
> return DimensionedQuantity<Y,DimensionedUnit<Model,angle_type>
> >(ret);
> }
>
> and then call it as you'd expect, getting the benefits of dimension
> verification :
>
> // test some trig stuff
> SI<double>::Angle theta = 0.375*_radians;
> SI<double>::Dimensionless sin_theta = sin(theta);
> SI<double>::Angle thetap = asin(sin_theta);
>
> double tmp = sin_theta;
>
> std::cout << theta << std::endl
> << sin_theta << std::endl
> << thetap << std::endl;

You want to redefine the trig functions to only take SI<double>::Angle
units? The trig functions don't take things with units, they take
numbers. It is completely reasonable and common to take sin(A/B),
where A and B both have the same units. You would require people to
write sin(radians *A/B), which is just wrong.

> > Degrees and gradians, on the other hand, definitly have units.
>
> Of what? They're just alternative ways of measuring the same thing :
> distance along an arc of a
> circle relative to that circle's perimeter. Degrees just define the
> unit circle to have a circumferance of
> 360 instead of 2 pi...

You don't normally put degrees or gradians into a Taylor series. You
do that all the time with radians. It is true that you can convert a
degree to a radian, but you can also convert a centimeter to a second
using the rather common conversion factor of the speed of light.

Regards,
Walter Landry
wlandry_at_[hidden]


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk