Example #1
0
        // The Lanczos approximation, should only be good for z >= 0.5,
        // but we get the right answers anyway.
        private static double gamma(double z)
        {
            double[] p = new double[8]
            {
                676.5203681218851,
                -1259.1392167224028,
                771.32342877765313,
                -176.61502916214059,
                12.507343278686905,
                -0.13857109526572012,
                9.9843695780195716e-6,
                1.5056327351493116e-7
            };
            z -= 1.0;
            double x = 0.99999999999980993;             // Unnecessary precision

            for (int i = 0; i < 8; i++)
            {
                double pval = p[i];
                x += pval / (z + i + 1);
            }
            double t = z + 8.0 - 0.5;

            return(Math.Sqrt(2.0 * Math.PI) * Math.Pow(t, z + 0.5) * Math.Exp(-t) * x);
        }
Example #2
0
        public static H3.Cell[] CalcCellsSmart(Sphere[] mirrors, H3.Cell[] cells, Settings settings, int desiredCount)
        {
            double t1 = 80;
            double t2 = 130;

            // I found that log(1/thresh)/log(count) was relatively constant,
            // so we'll extrapolate that to get close to the right number of edges.
            double OneOverThresh = t1;

            settings.Threshold = 1 / OneOverThresh;
            H3.Cell[] result = CalcCells(mirrors, cells, settings);
            int       count1 = result.Length;

            System.Console.WriteLine(string.Format("count1: {0}", count1));

            OneOverThresh      = t2;
            settings.Threshold = 1 / OneOverThresh;
            result             = CalcCells(mirrors, cells, settings);
            int count2 = result.Length;

            System.Console.WriteLine(string.Format("count2: {0}", count2));

            double slope           = (Math.Log(count2) - Math.Log(count1)) / (Math.Log(t2) - Math.Log(t1));
            double logDesiredCount = Math.Log((double)desiredCount);
            double temp            = Math.Log(t2) + (logDesiredCount - Math.Log(count2)) / slope;

            settings.Threshold = 1 / Math.Exp(temp);
            System.Console.WriteLine(string.Format("Setting threshold to: {0}", settings.Threshold));
            return(CalcCells(mirrors, cells, settings));
        }
        public static float[,] CalculateGaussianKernel(int W, double sigma)
        {
            float[,] kernel = new float[W, W];
            double mean = W / 2.0;
            float  sum  = 0.0f;

            for (int x = 0; x < W; ++x)
            {
                for (int y = 0; y < W; ++y)
                {
                    kernel[x, y] = (float)(Math.Exp(-0.5 * (Math.Pow((x - mean) / sigma, 2.0) + Math.Pow((y - mean) / sigma, 2.0)))
                                           / (2 * Math.PI * sigma * sigma));
                    sum += kernel[x, y];
                }
            }

            for (int x = 0; x < W; ++x)
            {
                for (int y = 0; y < W; ++y)
                {
                    kernel[x, y] *= (1.0f) / sum;
                }
            }

            return(kernel);
        }
Example #4
0
        /// <summary>
        /// From the virtual math museum
        /// </summary>
        public static Vector3D Dini2(Vector3D disk)
        {
            Vector3D uv = DiskToUpper(disk);
            double   u  = Math.Log(uv.Y);
            //double v = DonHatch.acosh( 1 + ( Math.Pow( uv.X, 2 ) + 0 ) / ( 2 * Math.Pow( uv.Y, 2 ) ) ) ;
            //if( uv.X < 0 )
            //	v *= -1;
            double v = uv.X;

            if (u <= -4 || u > 4 ||
                v < -6 * Math.PI || v > 6 * Math.PI)
            {
                return(Infinity.InfinityVector);
            }

            double psi = 0.5;

            psi *= Math.PI;
            double sinpsi = Math.Sin(psi);
            double cospsi = Math.Cos(psi);
            double g      = (u - cospsi * v) / sinpsi;
            double s      = Math.Exp(g);
            double r      = (2 * sinpsi) / (s + 1 / s);
            double t      = r * (s - 1 / s) * 0.5;

            return(new Vector3D(u - t, r * Math.Cos(v), r * Math.Sin(v)));
        }
Example #5
0
 /// <summary>
 /// Handles the calculation for hyperbolic cosecant.
 /// </summary>
 /// <param name="x">A double to be evaluated.</param>
 /// <returns>Return the hyperbolic cosecant of an angle specified in radians.</returns>
 public static double HyperbolicCosecant(double x)
 {
     if ((MathObj.Exp(x) - MathObj.Exp(-x)) == 0)
     {
         return(-2);
     }
     return(2 / (MathObj.Exp(x) - MathObj.Exp(-x)));
 }
Example #6
0
        /// <summary>
        /// Handles the calculation for hyperbolic cotangent.
        /// </summary>
        /// <param name="x">A double to be evaluated.</param>
        /// <returns>Return the hyperbolic cotangent of a hyperbolic angle.</returns>
        public static double HyperbolicCotangent(double x)
        {
            //This is to handle a rounding diffrence between excel and EPPlus.
            var NaNChecker = (MathObj.Exp(x) + MathObj.Exp(-x)) / (MathObj.Exp(x) - MathObj.Exp(-x));

            if (NaNChecker.Equals(double.NaN))
            {
                return(1);
            }

            return((MathObj.Exp(x) + MathObj.Exp(-x)) / (MathObj.Exp(x) - MathObj.Exp(-x)));
        }
Example #7
0
        expm1(double x)
        {
            double u = Math.Exp(x);

            if (u == 1.0)
            {
                return(x);
            }
            if (u - 1.0 == -1.0)
            {
                return(-1);
            }
            return((u - 1.0) * x / Math.Log(u));
        }
Example #8
0
        /// <summary>
        /// Attempts to calculate approx 1.3M edges when the threshold is a minimum edge length.
        /// This is required for honeycombs with ideal or ultra-ideal cells
        /// </summary>
        public static Edge[] CalcEdgesSmart2(Sphere[] simplex, Edge[] edges, int desiredCount)
        {
            Settings s = new Settings();

            // I found that log(1/thresh)/log(count) was relatively constant,
            // so we'll extrapolate that to get close to the right number of edges.
            double OneOverThresh = 60;

            s.Threshold = 1 / OneOverThresh;
            Edge[] result = CalcEdges(simplex, edges, s);
            int    count1 = result.Length;

            OneOverThresh = 80;
            s.Threshold   = 1 / OneOverThresh;
            result        = CalcEdges(simplex, edges, s);
            int count2 = result.Length;

            double slope           = (Math.Log(count2) - Math.Log(count1)) / (Math.Log(80) - Math.Log(60));
            double logDesiredCount = Math.Log((double)desiredCount);
            double temp            = Math.Log(80) + (logDesiredCount - Math.Log(count2)) / slope;

            s.Threshold = 1 / Math.Exp(temp);
            return(CalcEdges(simplex, edges, s));
        }
Example #9
0
File: Es.cs Project: DotLab/Futilef
        public static float Ease(int esType, float t)
        {
            switch (esType)
            {
            case EsType.Quad:
            case EsType.QuadIn:       return(t * t);

            case EsType.QuadOut:      return(t * (2 - t));

            case EsType.QuadInOut:    return((t *= 2) < 1 ? .5f * t * t : .5f * (1 - (t - 1) * (t - 3)));

            case EsType.Cubic:
            case EsType.CubicIn:      return(t * t * t);

            case EsType.CubicOut:     return((t -= 1) * t * t + 1);

            case EsType.CubicInOut:   return((t *= 2) < 1 ? .5f * t * t * t : .5f * ((t -= 2) * t * t + 2));

            case EsType.Quart:
            case EsType.QuartIn:      return(t * t * t * t);

            case EsType.QuartOut:     return(1 - (t -= 1) * t * t * t);

            case EsType.QuartInOut:   return((t *= 2) < 1 ? .5f * t * t * t * t : .5f * (2 - (t -= 2) * t * t * t));

            case EsType.Quint:
            case EsType.QuintIn:      return(t * t * t * t * t);

            case EsType.QuintOut:     return((t -= 1) * t * t * t * t + 1);

            case EsType.QuintInOut:   return((t *= 2) < 1 ? .5f * t * t * t * t * t : .5f * ((t -= 2) * t * t * t * t + 2));

            case EsType.Sine:
            case EsType.SineIn:       return(1 - (float)Math.Cos(t * HalfPi));

            case EsType.SineOut:      return((float)Math.Sin(t * HalfPi));

            case EsType.SineInOut:    return(.5f * (1 - (float)Math.Cos(t * Pi)));

            case EsType.Expo:
            case EsType.ExpoIn:       return((float)Math.Exp(7 * (t - 1)));

            case EsType.ExpoOut:      return(1 - (float)Math.Exp(-7 * t));

            case EsType.ExpoInOut:    return((t *= 2) < 1 ? .5f * (float)Math.Exp(7 * (t - 1)) : .5f * (2 - (float)Math.Exp(-7 * (t - 1))));

            case EsType.Circ:
            case EsType.CircIn:       return(1 - (float)Math.Sqrt(1 - t * t));

            case EsType.CircOut:      return((float)Math.Sqrt(1 - (t -= 1) * t));

            case EsType.CircInOut:    return((t *= 2) < 1 ? .5f * (1 - (float)Math.Sqrt(1 - t * t)) : .5f * ((float)Math.Sqrt(1 - (t -= 2) * t) + 1));

            case EsType.Back:
            case EsType.BackIn:       return(t * t * (2.70158f * t - 1.70158f));

            case EsType.BackOut:      return((t -= 1) * t * (2.70158f * t + 1.70158f) + 1);

            case EsType.BackInOut:    return((t *= 2) < 1 ? .5f * (t * t * (3.5949095f * t - 2.5949095f)) : .5f * ((t -= 2) * t * (3.5949095f * t + 2.5949095f) + 2));

            case EsType.Elastic:
            case EsType.ElasticIn:    return((float)(-Math.Exp(7 * (t -= 1)) * Math.Sin((t - 0.075) * 20.9439510239)));

            case EsType.ElasticOut:   return((float)(Math.Exp(-7 * t) * Math.Sin((t - 0.075) * 20.9439510239) + 1));

            case EsType.ElasticInOut: return((t *= 2) < 1 ? (float)(-.5 * Math.Exp(7 * (t -= 1)) * Math.Sin((t - 0.1125) * 13.962634016)) : (float)(Math.Exp(-7 * (t -= 1)) * Math.Sin((t - 0.1125) * 13.962634016) * .5 + 1));

            case EsType.Bounce:
            case EsType.BounceIn:     return(1 - Es.Ease(EsType.BounceOut, 1 - t));

            case EsType.BounceOut:    return(t < 0.363636363636f ? 7.5625f * t * t : t < 0.727272727273f ? 7.5625f * (t -= 0.545454545455f) * t + .75f : t < 0.909090909091f ? 7.5625f * (t -= 0.818181818182f) * t + .9375f : 7.5625f * (t -= 0.954545454545f) * t + .984375f);

            case EsType.BounceInOut:  return((t *= 2) < 1 ? .5f * (1 - Es.Ease(EsType.BounceOut, 1 - t)) : .5f * (Es.Ease(EsType.BounceOut, t - 1) + 1));
            }

            return(t);
        }
Example #10
0
 /// <summary>
 /// http://www.wolframalpha.com/input/?i=1%2F+%281%2Be%5E%28-10*%28x-0.5%29%29%29
 /// </summary>
 private double Sigmoid(double input)
 {
     return(1 / (1 + Math.Exp(-BorderDiv * (input - 0.5))));
 }
Example #11
0
        cosh(double x)
        {
            double e_x = Math.Exp(x);

            return((e_x + 1.0 / e_x) * .5);
        }
Example #12
0
 // Hyperbolic Cosecant
 public static double HCosec(double x)
 {
     return(2 / (MathObj.Exp(x) - MathObj.Exp(-x)));
 }
Example #13
0
 // Hyperbolic Cosine
 public static double HCos(double x)
 {
     return((MathObj.Exp(x) + MathObj.Exp(-x)) / 2);
 }
Example #14
0
 /// <summary>
 /// Handles the calculation for Hyperbolic Secant.
 /// </summary>
 /// <param name="x">A double to be evaluated.</param>
 /// <returns>Returns the hyperbolic secant of an angle.</returns>
 public static double HyperbolicSecant(double x)
 {
     return(2 / (MathObj.Exp(x) + MathObj.Exp(-x)));
 }
Example #15
0
 private static int Math_Exp(ILuaState lua)
 {
     lua.PushNumber(Math.Exp(lua.L_CheckNumber(1)));
     return(1);
 }
Example #16
0
 public static double Exp(object self, double x)
 {
     return(SM.Exp(x));
 }
Example #17
0
 // Hyperbolic Secant
 public static double HSec(double x)
 {
     return(2 / (MathObj.Exp(x) + MathObj.Exp(-x)));
 }
Example #18
0
 public static double Exp(object self, [DefaultProtocol] double x)
 {
     return(SM.Exp(x));
 }
Example #19
0
 // Hyperbolic Tangent
 public static double HTan(double x)
 {
     return((MathObj.Exp(x) - MathObj.Exp(-x)) / (MathObj.Exp(x) + MathObj.Exp(-x)));
 }
Example #20
0
 // Hyperbolic Sine
 public static double HSin(double x)
 {
     return((MathObj.Exp(x) - MathObj.Exp(-x)) / 2);
 }