Jmol/Quaternions

From Proteopedia

(Difference between revisions)
Jump to: navigation, search
Line 88: Line 88:
<jmol><jmolButton><script>q1 = quaternion()</script><text>store first orientation</text></jmolButton></jmol>
<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.
+
After pressing the button above, rotate the model a bit or a lot. Now will will go back the first orientation, with a nice speed no matter how different they are:
-
<jmol><jmolButton><script>q2 = quaternion()</script><text>store second orientation</text></jmolButton></jmol>
+
<jmol><jmolButton><script>q2 = quaternion(); rotation = q2 / q1; rotangle = rotation%"theta"; duration = angle/45 + 0.1; moveto @duration quaternion @q1</script><text>back to first 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>
+
Line 101: Line 97:
q2 = quaternion() #Store second orientation
q2 = quaternion() #Store second orientation
rotation = q2 / q1 #rotation to get from q1 to q2
rotation = q2 / q1 #rotation to get from q1 to q2
-
angle = rotation%"theta" #Extract the rotation angle from the quaternion
+
rotangle = rotation%"theta" #Extract the rotation angle from the quaternion
-
angle = 2 * acos(rotation.w) #Alternative way to get the angle, avoids percent sign
+
rotangle = 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
moveto @duration quaternion @q1 # reorient the view back to q1 in duration seconds
moveto @duration quaternion @q1 # reorient the view back to q1 in duration seconds

Revision as of 17:56, 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