[vtkusers] Bug in vtkQuaternion

David Gobbi david.gobbi at gmail.com
Thu Dec 5 16:04:37 EST 2013


Hi Mengda,

The SetRotationAngleAndAxis(angle, x, y, z) method does not
directly set the quaternion elements, for that you would use the
method Set(w, x, y, z).

For SetRotationAngleAndAxis, it does not make sense to specify
xyz=(0,0,0) with a nonzero angle because (0,0,0) is not a valid axis.

  David

On Thu, Dec 5, 2013 at 1:53 PM, Mengda Wu <wumengda at gmail.com> wrote:
> Hi all,
>
>    I think there is a bug in vtkQuaternion<T>::SetRotationAngleAndAxis. What
> if I want to
> set angle=1.0 and xyz=(0, 0, 0)? I need an identity matrix from this
> quaternion. Should it call this->Set(1.0, 0.0, 0.0, 0.0) instead of
> this->Set(0.0, 0.0, 0.0, 0.0) in this case?
>
> Thanks,
> Mengda
>
>
>
> The code is pasted here:
>
> template<typename T> void
> vtkQuaternion<T>::SetRotationAngleAndAxis (const T& angle,
>                                            const T& x,
>                                            const T& y,
>                                            const T& z)
> {
>   T axisNorm = x*x + y*y + z*z;
>   if (axisNorm != 0.0)
>     {
>     T w = cos(angle / 2.0);
>     this->SetW(w);
>
>     T f = sin( angle / 2.0);
>     this->SetX((x / axisNorm) * f);
>     this->SetY((y / axisNorm) * f);
>     this->SetZ((z / axisNorm) * f);
>     }
>   else
>     {
>     this->Set(0.0, 0.0, 0.0, 0.0);
>     }
> }


More information about the vtkusers mailing list