From: Andy Little (andy_at_[hidden])
Date: 2006-06-12 19:59:11
"John Phillips" wrote
> Andy Little wrote:
>> AFAIK a vector classically represents a magnitude and direction without more
>> information though, so the vector would be a position vector
> Yes, anything that is a representation of a magnitude and a direction
> is, in the math and physics senses of the word, a vector. Then there are
> different representations of that vector, and that is where it is
> possible for mixed units to appear.
> In general, the only representation that has no concerns about mixed
> units is cartesian coordinates in a space where the sense of scale in
> all directions has the same units. The x, y and z positions in cartesian
> 3 space is an example. However, that same vector is represented by a
> magnitude and 2 direction angles in spherical 3 space, and there is no a
> priori reason to prefer one representation to another. The choice of
> representation is always current application dependent.
In creating C++ types, my first thought would be to keep the cartesian and polar
types separate for efficiency reasons. If necessary ( which I dont't see it
would) a polymorphic_vector could provide the interface of both types.
Regarding a cartesian_vector (I'm not sure if that is technically the correct
nomenclature...?) I originally wrote it with a separate template
parameter for each element. There is no runtime cost but there are other costs.
One is in writing code for the type. An addition would require 6 template
parameters (allowing for implicit conversions) not 2. The second is in
compilation time and the third is in additional documentation. A fourth is
design complexities, should all the elements be addable for example.
My current thinking is that it is better to design a type with the minimal
interface which will cover some reasonable percentage of use. It is notable that
in the PQS review,two reviewers have stated that the design of the so-called
t1_quantity type in PQS is overcomplicated. Two decisions complicated the design
of t1_quantity. The first was the requirement to distinguish dimensionally
equivalent quantities (torque and energy say). The second was the use of
rational rather than integer powers of dimension. The type would be considerably
leaner without these requirements, but they were a result of responding to
demands for more flexibility and took considerable time to implement.
> Thus, for some not explicitly defined potential vector library it is
> possible to have mixed units in even the simplest of applications.
> 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
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk