Boost logo

Boost :

From: Geoffrey Irving (irving_at_[hidden])
Date: 2006-06-13 12:30:39


On Tue, Jun 13, 2006 at 05:31:58PM +0200, Janek Kozicki wrote:
> Andy Little said: (by the date of Tue, 13 Jun 2006 00:59:11 +0100)
>
> > > There are also spaces where the units (or more accurately, the
> > > dimensions) are not the same in all directions, so any vectors in those
> > > spaces will have mixed units in any coordinate system. A commonly used
> > > one is called "phase space" and it includes the position and momentum
> > > variables for a system all in the same space. Thinking of them together
> > > turns out to be quite important in some applications, so the example can
> > > be quite meaningful for some people.
> >
> > That is interesting, though I find anything beyond the usual space difficult to
> > visualise. The ability to visualise things such as this seems to be what marks
> > out mathematicians.
>
>
> ... and engineers? physicians? I'm not sure to which category I could
> belong (certainly not mathematician) but "phase space" is quite common
> when working with engineering problems. It is the most handy way to
> represent what is going on in any given point of space. However vector
> operations between vectors in "phase space" are different than
> dot_product and cross_product. Those two operations make no sense in fact.
>
> It is although common to multiply such vectors by some matrices...

I would suggest that instead of trying to make an extremely general vector
class, it'd be better to make an extremely specific vector class, together
with an extremely general way to other vector classes.

Specifically, you can make vector3 (or vector<3>, perhaps) a
straightforward single unit Euclidean vector. It can have L2 norms and
L^inf norms and cross products and all the operations that are undefined
for vectors with components of different units. Then we could define a
vector space variant of boost::operators to convert any tuple-like type
into a vector space type. If you wanted phase space, you'd do something
like this:

template<class Q,class P>
class phase_vector:public boost::vector_operators<phase_vector>
{
public:
    static const int vector_operators_dimension = 2;

    vector<Q> position
    vector<P> momentum;

    phase_vector(const vector<Q>& position,const vector<P>& momentum)
        :position(position),momentum(momentum)
    {}

    // these would need to be generalized to get<n>()
    vector<Q>& first()
    {return position;}

    vector<P>& second()
    {return momentum;}
};

and the vector_operators class would fill in scalar multiplication and
addition-related operators. In my opinion, this would be far more
useful than writing phase space as

vector<m,m,m,kg_m_div_s,kg_m_div_s,kg_m_div_s>

Geoffrey


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