<div dir="ltr"><div><div><div><div><div>Thanks a lot for your reply. <br><br>But for the identity quaternion (1, 0, 0, 0), the axis is indeed (0,0,0).<br></div>This is related to GetRotationAngleAndAxis, that function will give a nozero angle and axis (0,0,0) for the identity quaternion. <br>
</div>Then if I plug this result to SetRotationAngleAndAxis, I will get a quaternion (0,0,0,0), which does not make sense.<br></div>Then if I use ToMatrix3x3 on the quaternion (0,0,0,0), which will be wrong.<br><br></div>
So I suggest to change <br><br>template<typename T> void<br>vtkQuaternion<T>::SetRotationAngleAndAxis (const T& angle,<br> const T& x,<br> const T& y,<br>
const T& z)<br>{<br> T axisNorm = x*x + y*y + z*z;<br> if (axisNorm != 0.0)<br> {<br> T w = cos(angle / 2.0);<br> this->SetW(w);<br><br> T f = sin( angle / 2.0);<br>
this->SetX((x / axisNorm) * f);<br> this->SetY((y / axisNorm) * f);<br> this->SetZ((z / axisNorm) * f);<br> }<br> else if ( angle != 0.0 )<br> {<br> this->Set(1.0, 0.0, 0.0, 0.0);<br> }<br>
</div> else<br> {<br> this->Set(0.0, 0.0, 0.0, 0.0);<br> }<br><div>}<br><br></div><div>How is that?<br><br></div><div>Mengda<br></div><div><div class="gmail_extra"><br><br><div class="gmail_quote">On Thu, Dec 5, 2013 at 4:04 PM, David Gobbi <span dir="ltr"><<a href="mailto:david.gobbi@gmail.com" target="_blank">david.gobbi@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi Mengda,<br>
<br>
The SetRotationAngleAndAxis(angle, x, y, z) method does not<br>
directly set the quaternion elements, for that you would use the<br>
method Set(w, x, y, z).<br>
<br>
For SetRotationAngleAndAxis, it does not make sense to specify<br>
xyz=(0,0,0) with a nonzero angle because (0,0,0) is not a valid axis.<br>
<span class=""><font color="#888888"><br>
David<br>
</font></span><div class=""><div class="h5"><br>
On Thu, Dec 5, 2013 at 1:53 PM, Mengda Wu <<a href="mailto:wumengda@gmail.com">wumengda@gmail.com</a>> wrote:<br>
> Hi all,<br>
><br>
> I think there is a bug in vtkQuaternion<T>::SetRotationAngleAndAxis. What<br>
> if I want to<br>
> set angle=1.0 and xyz=(0, 0, 0)? I need an identity matrix from this<br>
> quaternion. Should it call this->Set(1.0, 0.0, 0.0, 0.0) instead of<br>
> this->Set(0.0, 0.0, 0.0, 0.0) in this case?<br>
><br>
> Thanks,<br>
> Mengda<br>
><br>
><br>
><br>
> The code is pasted here:<br>
><br>
> template<typename T> void<br>
> vtkQuaternion<T>::SetRotationAngleAndAxis (const T& angle,<br>
> const T& x,<br>
> const T& y,<br>
> const T& z)<br>
> {<br>
> T axisNorm = x*x + y*y + z*z;<br>
> if (axisNorm != 0.0)<br>
> {<br>
> T w = cos(angle / 2.0);<br>
> this->SetW(w);<br>
><br>
> T f = sin( angle / 2.0);<br>
> this->SetX((x / axisNorm) * f);<br>
> this->SetY((y / axisNorm) * f);<br>
> this->SetZ((z / axisNorm) * f);<br>
> }<br>
> else<br>
> {<br>
> this->Set(0.0, 0.0, 0.0, 0.0);<br>
> }<br>
> }<br>
</div></div></blockquote></div><br></div></div></div>