<div dir="ltr"><div>BTW, I think the slerp function in vtkQuaternion also has issues:<br><br></div>What if I would like to interpolate an identity quaternion (no rotation) with an slightly non-identity (a slight rotation). Then axis0=(0,0,0) and e.g. axis1=(1,0,0), will the result be wrong?<br>
</div><div class="gmail_extra"><br><br><div class="gmail_quote">On Thu, Dec 5, 2013 at 5:30 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:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">The unit quaternion is qw,qx,qy,qz = (1,0,0,0).  But (qx,qy,qz) is not<br>
the &quot;axis&quot;.  The axis is what you get when you divide (qx,qy,qz) by<br>
sin(theta/2).<br>
<br>
An identity quaternion is (1, 0, 0, 0), but it is wrong to say that<br>
for the identity quaternion the axis is (0,0,0).  The axis of an<br>
identity quaternion could be anything, because the axis of an identity<br>
quaternion is (0,0,0) / sin(0/2), hence &quot;undefined&quot;.<br>
<div class="HOEnZb"><div class="h5"><br>
<br>
<br>
On Thu, Dec 5, 2013 at 3:05 PM, Mengda Wu &lt;<a href="mailto:wumengda@gmail.com">wumengda@gmail.com</a>&gt; wrote:<br>
&gt; OK. I am a little confused.<br>
&gt; For an identity quaternion. The code is now<br>
&gt; template&lt;typename T&gt; void vtkQuaternion&lt;T&gt;::ToIdentity()<br>
&gt;<br>
&gt; {<br>
&gt;   this-&gt;Set(1.0, 0.0 ,0.0, 0.0);<br>
&gt; }<br>
&gt;<br>
&gt; which means the axis is (0,0,0). Isn&#39;t (0,0,0) a good way to represent<br>
&gt; undefined axis?<br>
&gt; So how to represent an identity matrix (no rotation) with a quaternion?<br>
&gt; Should it be (1, 0, 0, 0) or (0, 0, 0, 0)?<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; On Thu, Dec 5, 2013 at 4:30 PM, David Gobbi &lt;<a href="mailto:david.gobbi@gmail.com">david.gobbi@gmail.com</a>&gt; wrote:<br>
&gt;&gt;<br>
&gt;&gt; You say that for the identity quaternion the axis is (0,0,0) but that<br>
&gt;&gt; is not really true.  For the identity quaternion, the axis is<br>
&gt;&gt; undefined.<br>
&gt;&gt;<br>
&gt;&gt; If you call SetRotationAngleAndAxis(1,0,0,0), then you are passing<br>
&gt;&gt; invalid parameters to the method.  To get the identity quaternion, you<br>
&gt;&gt; need to set the angle to zero, not to one.<br>
&gt;&gt;<br>
&gt;&gt; I agree that the code should have an extra check, but it should be the<br>
&gt;&gt; opposite of what you have in your sample code.  It should give the<br>
&gt;&gt; identity quaternion if the angle is zero:<br>
&gt;&gt;<br>
&gt;&gt;    else if ( angle == 0.0 )<br>
&gt;&gt;      {<br>
&gt;&gt;      this-&gt;Set(1.0, 0.0, 0.0, 0.0);<br>
&gt;&gt;      }<br>
&gt;&gt;   else<br>
&gt;&gt;     {<br>
&gt;&gt;     this-&gt;Set(0.0, 0.0, 0.0, 0.0);<br>
&gt;&gt;     }<br>
&gt;&gt;<br>
&gt;&gt;  David<br>
&gt;&gt;<br>
&gt;&gt; On Thu, Dec 5, 2013 at 2:14 PM, Mengda Wu &lt;<a href="mailto:wumengda@gmail.com">wumengda@gmail.com</a>&gt; wrote:<br>
&gt;&gt; &gt; Thanks a lot for your reply.<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; But for the identity quaternion (1, 0, 0, 0), the axis is indeed<br>
&gt;&gt; &gt; (0,0,0).<br>
&gt;&gt; &gt; This is related to GetRotationAngleAndAxis, that function will give a<br>
&gt;&gt; &gt; nozero<br>
&gt;&gt; &gt; angle and axis (0,0,0) for the identity quaternion.<br>
&gt;&gt; &gt; Then if I plug this result to SetRotationAngleAndAxis, I will get a<br>
&gt;&gt; &gt; quaternion (0,0,0,0), which does not make sense.<br>
&gt;&gt; &gt; Then if I use ToMatrix3x3 on the quaternion (0,0,0,0), which will be<br>
&gt;&gt; &gt; wrong.<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; So I suggest to change<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; template&lt;typename T&gt; void<br>
&gt;&gt; &gt; vtkQuaternion&lt;T&gt;::SetRotationAngleAndAxis (const T&amp; angle,<br>
&gt;&gt; &gt;                                            const T&amp; x,<br>
&gt;&gt; &gt;                                            const T&amp; y,<br>
&gt;&gt; &gt;                                            const T&amp; z)<br>
&gt;&gt; &gt; {<br>
&gt;&gt; &gt;   T axisNorm = x*x + y*y + z*z;<br>
&gt;&gt; &gt;   if (axisNorm != 0.0)<br>
&gt;&gt; &gt;     {<br>
&gt;&gt; &gt;     T w = cos(angle / 2.0);<br>
&gt;&gt; &gt;     this-&gt;SetW(w);<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;     T f = sin( angle / 2.0);<br>
&gt;&gt; &gt;     this-&gt;SetX((x / axisNorm) * f);<br>
&gt;&gt; &gt;     this-&gt;SetY((y / axisNorm) * f);<br>
&gt;&gt; &gt;     this-&gt;SetZ((z / axisNorm) * f);<br>
&gt;&gt; &gt;     }<br>
&gt;&gt; &gt;   else if ( angle != 0.0 )<br>
&gt;&gt; &gt;     {<br>
&gt;&gt; &gt;     this-&gt;Set(1.0, 0.0, 0.0, 0.0);<br>
&gt;&gt; &gt;     }<br>
&gt;&gt; &gt;  else<br>
&gt;&gt; &gt;    {<br>
&gt;&gt; &gt;    this-&gt;Set(0.0, 0.0, 0.0, 0.0);<br>
&gt;&gt; &gt;    }<br>
&gt;&gt; &gt; }<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; How is that?<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; Mengda<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; On Thu, Dec 5, 2013 at 4:04 PM, David Gobbi &lt;<a href="mailto:david.gobbi@gmail.com">david.gobbi@gmail.com</a>&gt;<br>
&gt;&gt; &gt; wrote:<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; Hi Mengda,<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; The SetRotationAngleAndAxis(angle, x, y, z) method does not<br>
&gt;&gt; &gt;&gt; directly set the quaternion elements, for that you would use the<br>
&gt;&gt; &gt;&gt; method Set(w, x, y, z).<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; For SetRotationAngleAndAxis, it does not make sense to specify<br>
&gt;&gt; &gt;&gt; xyz=(0,0,0) with a nonzero angle because (0,0,0) is not a valid axis.<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt;   David<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; 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;&gt; &gt;&gt; &gt; Hi all,<br>
&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt; &gt;    I think there is a bug in<br>
&gt;&gt; &gt;&gt; &gt; vtkQuaternion&lt;T&gt;::SetRotationAngleAndAxis.<br>
&gt;&gt; &gt;&gt; &gt; What<br>
&gt;&gt; &gt;&gt; &gt; if I want to<br>
&gt;&gt; &gt;&gt; &gt; set angle=1.0 and xyz=(0, 0, 0)? I need an identity matrix from this<br>
&gt;&gt; &gt;&gt; &gt; quaternion. Should it call this-&gt;Set(1.0, 0.0, 0.0, 0.0) instead of<br>
&gt;&gt; &gt;&gt; &gt; this-&gt;Set(0.0, 0.0, 0.0, 0.0) in this case?<br>
&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt; &gt; Thanks,<br>
&gt;&gt; &gt;&gt; &gt; Mengda<br>
&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt; &gt; The code is pasted here:<br>
&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt; &gt; template&lt;typename T&gt; void<br>
&gt;&gt; &gt;&gt; &gt; vtkQuaternion&lt;T&gt;::SetRotationAngleAndAxis (const T&amp; angle,<br>
&gt;&gt; &gt;&gt; &gt;                                            const T&amp; x,<br>
&gt;&gt; &gt;&gt; &gt;                                            const T&amp; y,<br>
&gt;&gt; &gt;&gt; &gt;                                            const T&amp; z)<br>
&gt;&gt; &gt;&gt; &gt; {<br>
&gt;&gt; &gt;&gt; &gt;   T axisNorm = x*x + y*y + z*z;<br>
&gt;&gt; &gt;&gt; &gt;   if (axisNorm != 0.0)<br>
&gt;&gt; &gt;&gt; &gt;     {<br>
&gt;&gt; &gt;&gt; &gt;     T w = cos(angle / 2.0);<br>
&gt;&gt; &gt;&gt; &gt;     this-&gt;SetW(w);<br>
&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt; &gt;     T f = sin( angle / 2.0);<br>
&gt;&gt; &gt;&gt; &gt;     this-&gt;SetX((x / axisNorm) * f);<br>
&gt;&gt; &gt;&gt; &gt;     this-&gt;SetY((y / axisNorm) * f);<br>
&gt;&gt; &gt;&gt; &gt;     this-&gt;SetZ((z / axisNorm) * f);<br>
&gt;&gt; &gt;&gt; &gt;     }<br>
&gt;&gt; &gt;&gt; &gt;   else<br>
&gt;&gt; &gt;&gt; &gt;     {<br>
&gt;&gt; &gt;&gt; &gt;     this-&gt;Set(0.0, 0.0, 0.0, 0.0);<br>
&gt;&gt; &gt;&gt; &gt;     }<br>
&gt;&gt; &gt;&gt; &gt; }<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;<br>
&gt;<br>
</div></div></blockquote></div><br></div>