[vtkusers] rotating vtkProp3D using quaternions

Sergio Aguirre sergio.aguirre at gmail.com
Thu Sep 1 11:42:03 EDT 2011


Sorry everyone... the line below
vtkMath::Matrix3x3ToQuaternion(styQS, qi);

Should be qs not qi
vtkMath::Matrix3x3ToQuaternion(styQS, qs);

Sergio

On Thu, Sep 1, 2011 at 8:27 AM, Sergio Aguirre <sergio.aguirre at gmail.com>wrote:

> Hi everyone.
>
> I am trying to rotate a vtkProp3D by using quaternions.
>
> Basically I have a line (defined by vtkLineSource, mapper & actor) that
> when its end point is inside the bounds of an object (vtkProp3D) I would
> like to use to rotate + translate that object following the line.
>
> What I am doing now is:
>
> Using
> double qs[4], qf[4], qt[4], styQS[3][3], styQF[3][3];
>
> 1 - Save the initial matrix4x4 (styPoseE) of the line's end point and
> generate a start-quaternion "qs" a 3x3 matrix using vtkMath tools
>
> for (i=0; i<=2; i++)
> for (j=0; j<=2; j++)
> styQS[j][i] = styPoseE->GetElement(j,i);
>  vtkMath::Matrix3x3ToQuaternion(styQS, qi);
>
> 2 - I sample the line's movement and save the end matrix4x4 of the line's
> end point in an final-quaternion "qf"
>
> for (i=0; i<=2; i++)
>  for (j=0; j<=2; j++)
>  styQF[j][i] = styPoseE->GetElement(j,i);
> vtkMath::Matrix3x3ToQuaternion(styQF, qf);
>
> 3 - I calculate the conjugate of qs (qs')
>
> qs[1] = -qi[1];
> qs[2] = -qi[2];
> qs[3] = -qi[3];
>
> 4 - I calculate a quaternion "qt" that describes the rotation that
> describes the difference between qs and qt by qt = qf * qs'
>
> qt[0] = (qf[0]*qs[0] - qf[1]*qs[1] - qf[2]*qs[2] - qf[3]*qs[3]);
> qt[1] = (qf[0]*qs[1] + qf[1]*qs[0] + qf[2]*qs[3] - qf[3]*qs[2]);
> qt[2] = (qf[0]*qs[2] - qf[1]*qs[3] + qf[2]*qs[0] + qf[3]*qs[1]);
> qt[3] = (qf[0]*qs[3] + qf[1]*qs[2] - qf[2]*qs[1] + qf[3]*qs[0]);
>
> 5 - Also, I change the first element of qt (W) to degrees
>
> qt[0] = vtkMath::DegreesFromRadians(qt[0]);
>
> 6 - I apply the qt quaternion to the vtkProp3D object using
> ->RotateWXYZ();
>
> picked_object->RotateWXYZ(qt[0], qt[1], qt[2], qt[3]);
>
> However, the end result is not what I had expected. My questions are:
>
> - Does qt = qf * qs' describe the differential rotation between qf and qs?
> I what to apply only the differential so as to do a "soft pull" rotation of
> the vtkProp3D object and not have a new orientation defined by the line.
> - I had initially passed the vtkMatrix4x4 of the line (styPoseE) to the
> object (vtkProp3D) either using pokeMatrix or SetUserMatrix and do control
> the rotation of the object BUT only after its orientation is reset to that
> of the line and I want to only move it following the line.
> - Is there a different approach I should consider? This one just makes the
> object jitter uncontrollably
>
> Thank you for any suggestions.
>
> Sergio
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20110901/aa5bff66/attachment.htm>


More information about the vtkusers mailing list