/// <summary> /// Slerp the quaternion by t. /// </summary> public Quaternion3d Slerp(Quaternion3d from, Quaternion3d to, double t) { if (t <= 0) { return(new Quaternion3d(from)); } else if (t >= 1) { return(new Quaternion3d(to)); } else { double cosom = from.x * to.x + from.y * to.y + from.z * to.z + from.w * to.w; double absCosom = Math.Abs(cosom); double scale0; double scale1; if ((1 - absCosom) > 1e-6) { double omega = Safe_Acos(absCosom); double sinom = 1.0 / Math.Sin(omega); scale0 = Math.Sin((1.0 - t) * omega) * sinom; scale1 = Math.Sin(t * omega) * sinom; } else { scale0 = 1 - t; scale1 = t; } Quaternion3d res = new Quaternion3d(scale0 * from.x + scale1 * to.x, scale0 * from.y + scale1 * to.y, scale0 * from.z + scale1 * to.z, scale0 * from.w + scale1 * to.w); return(res.Normalized); } }
/// <summary> /// Create a rotation out of a vector. /// </summary> static public Matrix3x3d Rotate(Vector3d euler) { return(Quaternion3d.FromEuler(euler).ToMatrix3x3d()); }