(* Visualizing Quaternions: Chapter 29: Table 29.1: page 379 Mathematica Code for the 4x4 orthogonal rotation matrix in terms of a double quaternion. Copyright 2006, Trustees of Indiana University These files may be freely copied for personal and educational uses provided these lines are included. Full License available at: visualizingquaternions_license.txt *) QQTo4DRot[p_List,q_List] := Module[{q0= q[[1]], q1=q[[2]], q2 = q[[3]], q3 = q[[4]], p0= p[[1]], p1=p[[2]], p2 = p[[3]], p3 = p[[4]]}, {{p0*q0 + p1*q1 + p2*q2 + p3*q3, p1*q0 - p0*q1 - p3*q2 + p2*q3, p2*q0 + p3*q1 - p0*q2 - p1*q3, p3*q0 - p2*q1 + p1*q2 - p0*q3}, {(-(p1*q0) + p0*q1 - p3*q2 + p2*q3), (p0*q0 + p1*q1 - p2*q2 - p3*q3), (-(p3*q0) + p2*q1 + p1*q2 - p0*q3), (p2*q0 + p3*q1 + p0*q2 + p1*q3)}, {(-(p2*q0) + p3*q1 + p0*q2 - p1*q3), (p3*q0 + p2*q1 + p1*q2 + p0*q3), (p0*q0 - p1*q1 + p2*q2 - p3*q3), (-(p1*q0) - p0*q1 + p3*q2 + p2*q3)}, {(-(p3*q0) - p2*q1 + p1*q2 + p0*q3), (-(p2*q0) + p3*q1 - p0*q2 + p1*q3), (p1*q0 + p0*q1 + p3*q2 + p2*q3), (p0*q0 - p1*q1 - p2*q2 + p3*q3)}}]