Jmol/Quaternions

From Proteopedia

(Difference between revisions)
Jump to: navigation, search
Line 85: Line 85:
==Interpreting a rotation==
==Interpreting a rotation==
For the second example script, I wanted to rotate the view back to the initial orientation. For small adjustments, I wanted it to take a small time, while for larger adjustment, I wanted to spend enough time that you can easily follow. The Jmol moveto command takes a duration for the entire rotation as a parameter. If I set this to a fixed value, it would be too slow for small adjustments or too fast for large rotations. So I had to figure out by how many degrees I would rotate first, and then decide on the timing accordingly.
For the second example script, I wanted to rotate the view back to the initial orientation. For small adjustments, I wanted it to take a small time, while for larger adjustment, I wanted to spend enough time that you can easily follow. The Jmol moveto command takes a duration for the entire rotation as a parameter. If I set this to a fixed value, it would be too slow for small adjustments or too fast for large rotations. So I had to figure out by how many degrees I would rotate first, and then decide on the timing accordingly.
 +
 +
<jmol><jmolButton><script>q1 = quaternion()</script><text>store first orientation</text></jmolButton></jmol>
 +
 +
Rotate the model a bit or a lot. Then press next button.
 +
 +
<jmol><jmolButton><script>q2 = quaternion()</script><text>store second orientation</text></jmolButton></jmol>
 +
 +
Now will will go back the first orientation, with a nice speed no matter how different they are:
 +
 +
<jmol><jmolButton><script>rotation = q2 / q1; angle = rotation%"theta"; duration = angle/45 + 0.1; moveto @duration quaternion @q1</script><text>back to first orientation</text></jmolButton></jmol>
 +
Here are the relevant Jmol commands:
Here are the relevant Jmol commands:
-
q0 = quaternion
+
q1 = quaternion() #Store first orientation
 +
q2 = quaternion() #Store second orientation
 +
rotation = q2 / q1 #rotation to get from q1 to q2
angle = rotation%"theta" #Extract the rotation angle from the quaternion
angle = rotation%"theta" #Extract the rotation angle from the quaternion
angle = 2 * acos(rotation.w) #Alternative way to get the angle, avoids percent sign
angle = 2 * acos(rotation.w) #Alternative way to get the angle, avoids percent sign
duration = angle/45 + 0.1 #take one second per 45 degrees rotation, plus 0.1 sec
duration = angle/45 + 0.1 #take one second per 45 degrees rotation, plus 0.1 sec
-
qnew = rotation * q0 #figure out the new orientation
+
moveto @duration quaternion @q1 # reorient the view back to q1 in duration seconds
-
moveto @duration quaternion @qnew # reorient the view to qnew in duration seconds
+

Revision as of 17:53, 25 July 2019

Drag the structure with the mouse to rotate

Resources

http://sacredsoftware.net/tutorials/quaternion.html

Proteopedia Page Contributors and Editors (what is this?)

Karsten Theis

Personal tools