Example #1
0
 /**
  * sfericka interpolace pomoci kvaternionu
  *
  * @param q kvaternion
  * @param t vaha z intervalu <0;1>
  * @return nova instance Poin3D
  */
 public Quat slerp(Quat q, double t) {
   double c = this.dot(q);
   if (c > 1.0) c = 1.0;
   else if (c < -1.0) c = -1.0;
   double uhel = Math.acos(c);
   if (Math.abs(uhel) < 1.0e-5) return new Quat(this);
   double s = 1 / Math.sin(uhel);
   if (t >= 1) return new Quat(this);
   else if (t <= 0) return new Quat(q);
   else
     return new Quat(
             this.renorm()
                 .mul(Math.sin((1 - t) * uhel) * s)
                 .add(q.renorm().mul(Math.sin(t * uhel) * s)))
         .renorm();
 }