vectorDot[s_, 
          t_]  :=  s[[1]]*t[[1]]  +  s[[2]]*t[[2]]  +  
          s[[3]]*t[[3]];
vectorCross[s_, 
          t_]  :=  {s[[2]]*t[[3]] - s[[3]]*t[[2]], 
          s[[3]]*t[[1]] - s[[1]]*t[[3]], 
          s[[1]]*t[[2]] - s[[2]]*t[[1]]};

quatVector[v_]  :=  {0, v};
quatNorm[q_]  :=  
        q[[1]]*q[[1]] +  
          vectorDot[q[[2]], q[[2]]];
quatDot[p_, q_]  :=  
        p[[1]]*q[[1]]  +  
          vectorDot[p[[2]], q[[2]]];
quatInverse[q_]  :=  {q[[1]], -q[[2]]}/
          quatDot[q, q];
quatAdd[p_, q_]  :=  {p[[1]] + q[[1]], 
          p[[2]] + q[[2]]};
quatOrientation[t_, v_]  :=  {Cos[(t/2) Degree], 
          Sin[(t/2) Degree]*v};
quatMult[p_, 
        q_] := {p[[1]]*q[[1]] - vectorDot[p[[2]], q[[2]]], 
        p[[1]]*q[[2]] + q[[1]]*p[[2]] + 
          vectorCross[p[[2]], q[[2]]]}

quatRotVector[v_, 
          p_]  :=  N[
            quatMult[quatMult[p, quatVector[v]], 
              quatInverse[p]]][[2]];
  quatRotquat[
          q_, p_]  :=  
        N[quatMult[quatMult[p, q], quatInverse[p]]];

v1  = {4, 0, 4};
t  =  45;
x  =  {1, 0, 0};

o1  = quatOrientation[t, x]

quatRotVector[v1, o1]

quatMatrix[
        q_]  :=  {
s = 
          q[[1]]; 
vx = q[[2]][[1]]; 
        vy = q[[2]][[2]]; 
        vz = q[[2]][[3]]; 
{1 - 2*vy*vy - 
            2*vz*vz, 2*vx*vy - 2*s*vz, 
          2*vx*vz + 2*s*vy}, 
{2*vx*vy + 2*s*vz, 
          1 - 2*vx*vx - 2*vz*vz, 
          2*vy*vz - 2*s*vx}, 
{2*vx*vz - 2*s*vy, 
          2*vy*vz + 2*s*vx, 
          1 - 2*vx*vx - 2*vy*vy}
}

Matrix2Quat[
        M_] :=  
{
s = 
          Sqrt[M[[1]][[1]] + M[[2]][[2]] + M[[3]][[3]] + 1]/2; 
x = 
          Sqrt[(M[[1]][[1]] + 1 - 2*s*s)/
              2]; 
y = 
          Sqrt[(M[[2]][[2]] + 1 - 2*s*s)/
              2]; 
z = 
          Sqrt[(M[[3]][[3]] + 1 - 2*s*s)/
              2]; 
{s, {x, y, 
            z}}
}