/// <summary>
        ///
        /// </summary>
        /// <param name="color"></param>
        /// <returns></returns>
        public static Vector3d LABtoLCH(Vector3d color)
        {
            double l = color.X;
            double a = color.Y;
            double b = color.Z;

            double c = Math.Sqrt(a * a + b * b);
            double h = Math.Atan2(b, a);

            h = (h > 0.0) ? SlurMath.ToDegrees(h) : SlurMath.ToDegrees(360.0 - Math.Abs(h));

            return(new Vector3d(l, c, h));
        }
Example #2
0
        /// <summary>
        ///
        /// </summary>
        public static double Lerp(this double[] vector, double t)
        {
            int last = vector.Length - 1;

            t = SlurMath.Fract(t * last, out int i);

            if (i < 0)
            {
                return(vector[0]);
            }
            else if (i >= last)
            {
                return(vector[last]);
            }

            return(SlurMath.Lerp(vector[i], vector[i + 1], t));
        }
Example #3
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));
        }
Example #4
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="t"></param>
 /// <param name="from"></param>
 /// <param name="to"></param>
 /// <returns></returns>
 public static float Remap(float t, Intervalf from, Intervalf to)
 {
     return(SlurMath.Remap(t, from.A, from.B, to.A, to.B));
 }
Example #5
0
        /// <summary>
        /// Returns the signed minimum difference between the two angles.
        /// </summary>
        /// <param name="a0"></param>
        /// <param name="a1"></param>
        /// <returns></returns>
        public static double GetMinAngleDifference(double a0, double a1)
        {
            var d0 = SlurMath.Repeat(a0 - a1, D.TwoPi);

            return(d0 > D.Pi ? d0 - D.TwoPi : d0);
        }
Example #6
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="t"></param>
 /// <returns></returns>
 public double SmootherStep(double t)
 {
     return(SlurMath.SmootherStep(t, A, B));
 }
Example #7
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="t"></param>
 /// <returns></returns>
 public double Nearest(double t)
 {
     return(SlurMath.Nearest(t, A, B));
 }
Example #8
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="t"></param>
 public double Evaluate(double t)
 {
     return(SlurMath.Lerp(A, B, t));
 }
Example #9
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="t"></param>
 /// <param name="from"></param>
 /// <param name="to"></param>
 /// <returns></returns>
 public static double Remap(double t, Intervald from, Intervald to)
 {
     return(SlurMath.Remap(t, from.A, from.B, to.A, to.B));
 }
Example #10
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));
 }
Example #11
0
 /// <summary>
 ///
 /// </summary>
 public bool IsUnit(double tolerance = D.ZeroTolerance)
 {
     return(SlurMath.ApproxEquals(SquareLength, 1.0, tolerance));
 }
Example #12
0
        /// <summary>
        /// Returns the angle between two vectors.
        /// </summary>
        /// <param name="v0"></param>
        /// <param name="v1"></param>
        /// <returns></returns>
        public static double Angle(Vector2d v0, Vector2d v1)
        {
            var d = v0.SquareLength * v1.SquareLength;

            return(d > 0.0 ? SlurMath.AcosSafe(Dot(v0, v1) / Math.Sqrt(d)) : 0.0);
        }
Example #13
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="vector"></param>
 /// <param name="whole"></param>
 /// <returns></returns>
 public static Vector2d Fract(Vector2d vector, out Vector2i whole)
 {
     return(new Vector2d(
                SlurMath.Fract(vector.X, out whole.X),
                SlurMath.Fract(vector.Y, out whole.Y)));
 }
Example #14
0
 /// <summary>
 /// Returns a random vector which has components within the given interval.
 /// </summary>
 /// <param name="random"></param>
 /// <param name="t0"></param>
 /// <param name="t1"></param>
 /// <returns></returns>
 public static Vector2d NextVector2d(this Random random, double t0, double t1)
 {
     return(new Vector2d(
                SlurMath.Lerp(t0, t1, random.NextDouble()),
                SlurMath.Lerp(t0, t1, random.NextDouble())));
 }
Example #15
0
        /// <summary>
        /// Returns the minimum angle between two vectors.
        /// </summary>
        /// <param name="v0"></param>
        /// <param name="v1"></param>
        /// <returns></returns>
        public static float Angle(Vector3f v0, Vector3f v1)
        {
            var d = v0.SquareLength * v1.SquareLength;

            return(d > 0.0f ? SlurMath.AcosSafe(Dot(v0, v1) / SlurMath.Sqrt(d)) : 0.0f);
        }
Example #16
0
        /// <summary>
        /// Returns the signed angle between two vectors.
        /// </summary>
        /// <param name="v0"></param>
        /// <param name="v1"></param>
        /// <param name="up"></param>
        /// <returns></returns>
        public static float SignedAngle(Vector3f v0, Vector3f v1, Vector3f up)
        {
            var c = Cross(v0, v1);

            return(SlurMath.Atan2(c.Length * Math.Sign(Dot(c, up)), Dot(v0, v1)));
        }
Example #17
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="t"></param>
 public float Evaluate(float t)
 {
     return(SlurMath.Lerp(A, B, t));
 }
Example #18
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));
 }
Example #19
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="t"></param>
 /// <returns></returns>
 public float Normalize(float t)
 {
     return(SlurMath.Normalize(t, A, B));
 }
Example #20
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="t"></param>
 /// <returns></returns>
 public double Normalize(double t)
 {
     return(SlurMath.Normalize(t, A, B));
 }
Example #21
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="t"></param>
 /// <returns></returns>
 public float Nearest(float t)
 {
     return(SlurMath.Nearest(t, A, B));
 }
Example #22
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="t"></param>
 /// <returns></returns>
 public double Ramp(double t)
 {
     return(SlurMath.Ramp(t, A, B));
 }
Example #23
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="t"></param>
 /// <returns></returns>
 public float Ramp(float t)
 {
     return(SlurMath.Ramp(t, A, B));
 }
Example #24
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="t"></param>
 /// <returns></returns>
 public double Repeat(double t)
 {
     return(SlurMath.Repeat(t, A, B));
 }
Example #25
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="t"></param>
 /// <returns></returns>
 public float SmootherStep(float t)
 {
     return(SlurMath.SmootherStep(t, A, B));
 }
Example #26
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="t"></param>
 /// <returns></returns>
 public float Repeat(float t)
 {
     return(SlurMath.Repeat(t, A, B));
 }
Example #27
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));
 }