|
Boost : |
From: Andy Little (andy_at_[hidden])
Date: 2006-06-12 16:57:37
"Michael Fawcett" wrote
> On 6/9/06, Andy Little wrote:
>> In cases of vectors, I have only used vectors where all elements are one type
>> of
>> quantity. The vectors are used to represent position, direction and so on in
>> 3
>> dimensions. A container that holds different quantities I would consider to
>> be a
>> tuple. But I stress I am not an expert.
>
> I am not an expert either, but in practice I have used (incorrectly?
> should I have used a tuple or a custom data type?) vectors for
> representing latitude/longitude/altitude with mixed units. Something
> like vec3<double, unsigned short, double> for decimal degrees, meters,
> decimal degrees.
Well IMO this sounds more like a navigation coordinate(or whatever is the
standard name for it) , and this sounds specific enough to make it its own
class, maybe you could convert it to a vector relative to the center of the
earth:
struct nav_coord{
boost::pqs::angle::s latitude,longtitude;
boost::pqs::length::m altitude;
operator boost::pqs::three_d::vect<boost::pqs::length::m>();
};
AFAIK a vector classically represents a magnitude and direction without more
information though, so the vector would be a position vector
> I often need to move back and forth from those units
> to nautical miles and feet, and I bet a library like PQS would help me
> out more than meaningful variable names.
You could return the distance (or distance vector) from a distance function
(between two navigation coordinates presumably) in (say) meters. In PQS
conversions to non-SI units are automatic so the result can be assigned to ( a
vector in) nautical miles or feet. (In PQS vectors are designed to work this way
as well as scalars) :
/*
show that conversion works for vectors as well as scalars
NB not tested in pqs_3_1_1 release version
*/
// note:ideally its ..
//#include <boost/pqs/three_d/out/vect.hpp>
// but in pqs_3_1_1...
#include <boost/pqs/three_d/vect_out.hpp>
#include <boost/pqs/t1_quantity/types/out/length.hpp>
namespace pqs = boost::pqs;
int main()
{
typedef pqs::length::naut_mile naut_mile;
typedef pqs::length::ft foot;
pqs::three_d::vect<naut_mile> naut_mile_vect(
naut_mile(1),naut_mile(1),naut_mile(1)
);
pqs::three_d::vect<foot> ft_vect = naut_mile_vect;
std::cout << ft_vect <<'\n';
// convert absolute length of vect to meters FWIW
pqs::length::m length_of_vect = magnitude(ft_vect);
std::cout << length_of_vect <<'\n';
}
//output:
//[6076.12 ft, 6076.12 ft, 6076.12 ft]
//3207.76 m
> I am ambivalent about whether the vector should allow mixed data types
> or not. I could settle for using a tuple instead, as long as vector
> functions like normalize(my_vec3) or length(my_vec) worked on tuple
> types as well.
My guess is the nav coordinates would work best as a class? This would enable
for example conversion to from position vectors etc as above, which isnt
possible with a tuple.
regards
Andy Little
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk