----- Original Message -----
From: "Matthias Schabel"
Newsgroups: gmane.comp.lib.boost.user
To:
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 rather than
Vector.
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 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
#include
#include
#include
#include
#include <iostream>
#include <iomanip>
#include <cstddef>
using namespace std;
using namespace boost;
using namespace boost::units;
using namespace tjg_basic;
typedef quantity Position;
typedef quantity Displacement;
typedef quantity Velocity;
typedef quantitysi::plane_angle Angle;
typedef quantitysi::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