|
Boost : |
From: Matthias Schabel (boost_at_[hidden])
Date: 2003-12-10 11:02:35
>>> 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;
> 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...
Matthias
------------------------------------------------------------------------
---------------------------
Matthias Schabel, Ph.D.
Utah Center for Advanced Imaging Research
729 Arapeen Drive
Salt Lake City, UT 84108
801-587-9413 (work)
801-585-3592 (fax)
801-706-5760 (cell)
801-484-0811 (home)
mschabel at ucair med utah edu
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk