Boost logo

Boost :

From: Hugo Duncan (hugoduncan_at_[hidden])
Date: 2007-03-20 09:19:54


Hi,

We recently wrote some code that did some computaional mechanics and had
several bugs due to mixing frames of reference. Prompted by recent
discussions of affine spaces, I have developed some simple classes for
tracking different spaces, points and displacements at compile time.

eg.
    struct frame1 {};
    struct frame2 {};
    typedef ublas::bounded_vector<double,3> vector;

    typedef math::point<vector, frame1> point;
    typedef math::displacement<vector, frame1> displacement;

    point p1(ublas::scalar_vector<double>(3,1.));
    point p2(ublas::scalar_vector<double>(3,1.));
    displacement d1(ublas::scalar_vector<double>(3,1.));

    p2=p1+d1;
    d1=p1+d1; //fails
    p1=p1+p1; //fails

    vector p3(ublas::scalar_vector<double>(3,1.));
    vector d2(ublas::scalar_vector<double>(3,1.));
    math::point_ref<frame1>(p3)+=d1;
    math::point_ref<frame2>(p3)+=d1; // fails
    math::point_ref<frame1>(p3)+=math::displacement_ref<frame1>(d2);
    math::point_ref<frame2>(p3)+=math::displacement_ref<frame2>(d2);
    math::point_ref<frame1>(p3)+=math::displacement_ref<frame2>(d2); //
fails

The code is available in the math-geometry section of the boost vault at
http://www.boost-consulting.com/vault/index.php?direction=0&order=&directory=Math%20-%20Geometry&
as affine-0.0.3.tar.gz

Comments welcome on the utility of the approach and on the design are most
welcome.

Hugo


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