Boost logo

Ublas :

Subject: [ublas] function with ublas types
From: Denis Taniguchi (taniguchi_at_[hidden])
Date: 2009-03-12 18:01:46


Hi all,

I was trying to define a function that uses ublas vector type:

    template <class T>
    quaternion<T> rot_quat(const c_vector<T, 3> &vec, T angle)
    {
      T tmp = sin(0.5*angle);
      return quaternion<T>(cos(0.5*angle),
                           vec(0) * tmp,
                           vec(1) * tmp,
                           vec(2) * tmp);
    }

I can successfully use the function with the following line of code:

    quaternion<double> q = rot_quat(vec3(0.0, 0.0, 1.0), M_PI/4.0);

But this fails to compile with gcc 4.3.2 and boost 1.34.1:

    quaternion<double> q = rot_quat(vec3(0.0, 0.0, 0.5) + vec3(0.0, 0.0,
0.5), M_PI/4.0);

src/main.cpp:21: error: no matching function for call to
'rot_quat(boost::numeric::ublas::vector_binary<boost::numeric::ublas::c_vector<double, 3ul>, boost::numeric::ublas::c_vector<double, 3ul>, boost::numeric::ublas::scalar_plus<double, double> >, double)'

I think that the problem is that vec3(0.0, 0.0, 0.5) + vec3(0.0, 0.0,
0.5) is an vector_expression and it can't automatically cast to
c_vector<double, 3>. If I wanted something generic that would work in
any type of vector I would implement through vector_expressions but this
function has only meaning for bounded vectors of size 3.
Any ideas?
Best regards,

Denis