/// <summary>
        ///
        /// </summary>
        /// <param name="from"></param>
        /// <param name="to"></param>
        /// <returns></returns>
        public static Quaterniond CreateFromTo(Vector3d from, Vector3d to)
        {
            // impl refs
            // https://stackoverflow.com/questions/1171849/finding-quaternion-representing-the-rotation-from-one-vector-to-another
            // http://lolengine.net/blog/2013/09/18/beautiful-maths-quaternion-from-vectors

            if (!from.Unitize() || !to.Unitize())
            {
                return(Identity);
            }

            var ca = Vector3d.Dot(from, to);

            // parallel check
            if (SlurMath.ApproxEquals(Math.Abs(ca), 1.0))
            {
                //opposite check
                if (ca < 0.0)
                {
                    var perp = from.X < 1.0 ? from.CrossX : from.CrossY;
                    var t    = 1.0 / perp.Length;
                    return(new Quaterniond(perp.X * t, perp.Y * t, perp.Z * t, 0.0));
                }

                return(Identity);
            }

            // can assume axis is valid
            var axis = Vector3d.Cross(from, to);
            var q    = new Quaterniond(axis.X, axis.Y, axis.Z, ca + 1.0);

            q.Unitize();

            return(q);
        }
 /// <summary>
 ///
 /// </summary>
 /// <param name="other"></param>
 /// <param name="epsilon"></param>
 /// <returns></returns>
 public bool ApproxEquals(Quaterniond other, double epsilon = D.ZeroTolerance)
 {
     return
         (SlurMath.ApproxEquals(X, other.X, epsilon) &&
          SlurMath.ApproxEquals(Y, other.Y, epsilon) &&
          SlurMath.ApproxEquals(Z, other.Z, epsilon) &&
          SlurMath.ApproxEquals(W, other.W, epsilon));
 }
Exemple #3
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="epsilon"></param>
 /// <returns></returns>
 public bool IsSymmetric(double epsilon = D.ZeroTolerance)
 {
     return
         (SlurMath.ApproxEquals(M01, M10) &&
          SlurMath.ApproxEquals(M02, M20) &&
          SlurMath.ApproxEquals(M03, M30) &&
          SlurMath.ApproxEquals(M12, M21) &&
          SlurMath.ApproxEquals(M13, M31) &&
          SlurMath.ApproxEquals(M23, M32));
 }
Exemple #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="other"></param>
        /// <param name="epsilon"></param>
        /// <returns></returns>
        public bool ApproxEquals(ref Matrix4d other, double epsilon = D.ZeroTolerance)
        {
            return
                (SlurMath.ApproxEquals(M00, other.M00, epsilon) &&
                 SlurMath.ApproxEquals(M01, other.M01, epsilon) &&
                 SlurMath.ApproxEquals(M02, other.M02, epsilon) &&
                 SlurMath.ApproxEquals(M03, other.M03, epsilon) &&

                 SlurMath.ApproxEquals(M10, other.M10, epsilon) &&
                 SlurMath.ApproxEquals(M11, other.M11, epsilon) &&
                 SlurMath.ApproxEquals(M12, other.M12, epsilon) &&
                 SlurMath.ApproxEquals(M13, other.M13, epsilon) &&

                 SlurMath.ApproxEquals(M20, other.M20, epsilon) &&
                 SlurMath.ApproxEquals(M21, other.M21, epsilon) &&
                 SlurMath.ApproxEquals(M22, other.M22, epsilon) &&
                 SlurMath.ApproxEquals(M23, other.M23, epsilon) &&

                 SlurMath.ApproxEquals(M30, other.M30, epsilon) &&
                 SlurMath.ApproxEquals(M31, other.M31, epsilon) &&
                 SlurMath.ApproxEquals(M32, other.M32, epsilon) &&
                 SlurMath.ApproxEquals(M33, other.M33, epsilon));
        }
Exemple #5
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="other"></param>
 /// <param name="epsilon"></param>
 /// <returns></returns>
 public bool ApproxEquals(Intervald other, double epsilon = D.ZeroTolerance)
 {
     return
         (SlurMath.ApproxEquals(A, other.A, epsilon) &&
          SlurMath.ApproxEquals(B, other.B, epsilon));
 }
Exemple #6
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="other"></param>
 /// <param name="epsilon"></param>
 /// <returns></returns>
 public bool ApproxEquals(Intervalf other, float epsilon = F.ZeroTolerance)
 {
     return
         (SlurMath.ApproxEquals(A, other.A, epsilon) &&
          SlurMath.ApproxEquals(B, other.B, epsilon));
 }
 /// <summary>
 ///
 /// </summary>
 public bool IsUnit(double tolerance = D.ZeroTolerance)
 {
     return(SlurMath.ApproxEquals(SquareLength, 1.0, tolerance));
 }
Exemple #8
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="other"></param>
 /// <param name="epsilon"></param>
 /// <returns></returns>
 public bool ApproxEquals(AxisAngle3d other, double epsilon = D.ZeroTolerance)
 {
     return
         (SlurMath.ApproxEquals(_angle, other._angle, epsilon) &&
          _axis.ApproxEquals(other._axis, epsilon));
 }