<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&lt;typename T&gt; void<br>vtkQuaternion&lt;T&gt;::SetRotationAngleAndAxis (const T&amp; angle,<br>                                           const T&amp; x,<br>                                           const T&amp; y,<br>
                                           const T&amp; 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-&gt;SetW(w);<br><br>    T f = sin( angle / 2.0);<br>
    this-&gt;SetX((x / axisNorm) * f);<br>    this-&gt;SetY((y / axisNorm) * f);<br>    this-&gt;SetZ((z / axisNorm) * f);<br>    }<br>  else if ( angle != 0.0 )<br>    {<br>    this-&gt;Set(1.0, 0.0, 0.0, 0.0);<br>    }<br>
</div> else<br>   {<br>   this-&gt;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">&lt;<a href="mailto:david.gobbi@gmail.com" target="_blank">david.gobbi@gmail.com</a>&gt;</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 &lt;<a href="mailto:wumengda@gmail.com">wumengda@gmail.com</a>&gt; wrote:<br>
&gt; Hi all,<br>
&gt;<br>
&gt;    I think there is a bug in vtkQuaternion&lt;T&gt;::SetRotationAngleAndAxis. What<br>
&gt; if I want to<br>
&gt; set angle=1.0 and xyz=(0, 0, 0)? I need an identity matrix from this<br>
&gt; quaternion. Should it call this-&gt;Set(1.0, 0.0, 0.0, 0.0) instead of<br>
&gt; this-&gt;Set(0.0, 0.0, 0.0, 0.0) in this case?<br>
&gt;<br>
&gt; Thanks,<br>
&gt; Mengda<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; The code is pasted here:<br>
&gt;<br>
&gt; template&lt;typename T&gt; void<br>
&gt; vtkQuaternion&lt;T&gt;::SetRotationAngleAndAxis (const T&amp; angle,<br>
&gt;                                            const T&amp; x,<br>
&gt;                                            const T&amp; y,<br>
&gt;                                            const T&amp; z)<br>
&gt; {<br>
&gt;   T axisNorm = x*x + y*y + z*z;<br>
&gt;   if (axisNorm != 0.0)<br>
&gt;     {<br>
&gt;     T w = cos(angle / 2.0);<br>
&gt;     this-&gt;SetW(w);<br>
&gt;<br>
&gt;     T f = sin( angle / 2.0);<br>
&gt;     this-&gt;SetX((x / axisNorm) * f);<br>
&gt;     this-&gt;SetY((y / axisNorm) * f);<br>
&gt;     this-&gt;SetZ((z / axisNorm) * f);<br>
&gt;     }<br>
&gt;   else<br>
&gt;     {<br>
&gt;     this-&gt;Set(0.0, 0.0, 0.0, 0.0);<br>
&gt;     }<br>
&gt; }<br>
</div></div></blockquote></div><br></div></div></div>