code: public Matrix3 setToRotation (IQuaternion quat) {
          double qx = quat.x(), qy = quat.y(), qz = quat.z(), qw = quat.w();
          double xx = qx*qx, yy = qy*qy, zz = qz*qz;
          double xy = qx*qy, xz = qx*qz, xw = qx*qw;
          double yz = qy*qz, yw = qy*qw, zw = qz*qw;
          return set(1f - 2f*(yy + zz), 2f*(xy - zw), 2f*(xz + yw),
                     2f*(xy + zw), 1f - 2f*(xx + zz), 2f*(yz - xw),
                     2f*(xz - yw), 2f*(yz + xw), 1f - 2f*(xx + yy));
      }
docs: Sets this to a rotation matrix. The formula comes from the
  <a href="http://www.j3d.org/matrix_faq/matrfaq_latest.html">Matrix and Quaternion FAQ</a>.
  
  @return a reference to this matrix, for chaining.