|
Boost Users : |
Subject: Re: [Boost-users] [units] subtract_typeof_helper<> help!
From: Terry Golubiewski (tjgolubi_at_[hidden])
Date: 2010-05-19 20:10:23
----- Original Message -----
From: "Matthias Schabel" <boost_at_[hidden]>
Newsgroups: gmane.comp.lib.boost.user
To: <boost-users_at_[hidden]>
Sent: Wednesday, May 19, 2010 2:19 PM
Subject: Re: [units] subtract_typeof_helper<> help!
>> This version serves about as well, doesn't use [units], and uses very
>> little of [geometry].
>> terry
>
> I don't know what the main purpose of Boost.Geometry is... Boost.Units is
> intended to ensure compile-time dimensional correctness. It is probably
> only useful if your code is likely to have mixed use of vectors/points
> having different length metrics. The code posted here has no idea if the
> distances are in microns or furlongs and will happily mix the two without
> any warning.
>
> Matthias
What I'm struggling with is how to provide a units-aware Vector/Point system
for physical computation.
Currently, I'm favoring using units::quantity<U, Vector<double>> rather than
Vector<units::quantity<U>>.
I expected to use boost::geometry, but that didn't seem to provide much
benefit.
Now that I'm not using boost::geometry to implement Vector/Point, it might
be much easier to support Vector<units::quantity<U>> as well.
My example was an intermediate stage. The example file that I failed to
post looked like this, along with the sample output.
It is interesting that (somehow) the Point/Vector quantities figured
themselves out.
Its interesting because:
Vector = Point - Point
Point = Point + Vector
Vector = Vector + Vector
but _not_ Point = Point + Point
and the dot product
Scalar = Vector * Vector
#include "BasicVector.h"
#include <boost/units/systems/si.hpp>
#include <boost/units/systems/si/prefixes.hpp>
#include <boost/units/base_units/us/foot.hpp>
#include <boost/units/quantity.hpp>
#include <boost/units/io.hpp>
#include <iostream>
#include <iomanip>
#include <cstddef>
using namespace std;
using namespace boost;
using namespace boost::units;
using namespace tjg_basic;
typedef quantity<si::length, Point<double> > Position;
typedef quantity<si::length, Vector<double> > Displacement;
typedef quantity<si::velocity, Vector<double> > Velocity;
typedef quantity<si::plane_angle> Angle;
typedef quantity<si::time> Time;
int main() {
static const si::length m = si::meter;
static const si::time s = si::second;
Position p1 = Point<double>(1.0, 2.0, 3.0) * m;
Position p2 = Point<double>(4.0, 5.0, 6.0) * m;
Position p3 = Point<double>(3.0, 9.0, 4.0) * m;
Displacement disp1 = p2 - p1;
cout << disp1 << endl;
cout << abs(disp1) << endl;
cout << abs_squared(disp1) << endl;
p1 += disp1;
cout << p1 << endl;
Time dt = Time(0.1 * s);
Velocity v = (p3 - p2) / dt;
cout << v << endl;
return EXIT_SUCCESS;
} // main
Output:
<3 3 3> m
5.19615 m
27 m^2
(4 5 6) m
<-10 40 -20> m s^-1
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