Example #1
0
        public static float logCurve(float level, float initial, float steepness, float amplification)
        {
            float s = 1 / (float)Math.Log((steepness + 1), 10);
            float b = (float)(Math.Log((level + s), 10) - Math.Log(s, 10));

            return(initial + amplification * b);
        }
Example #2
0
        /// <summary>
        /// Calculates distance/bearing between two geographic locations on Rhumb line (loxodrome)
        /// </summary>
        /// <param name="origin">origin location in geographic degrees</param>
        /// <param name="destination">destination location in geographic degrees</param>
        /// <param name="radius">radius of a geographic sphere, in kilometers</param>
        /// <remarks>radius defaults to Earth's mean radius</remarks>
        public static GeoRhumb GetRhumb(GeoPoint origin, GeoPoint destination, double radius = GeoGlobal.Earths.Radius)
        {
            origin      = origin.ToRadians();
            destination = destination.ToRadians();
            var dLat = (destination.Latitude - origin.Latitude);
            var dLon = (destination.Longitude - origin.Longitude);

            var tDestination = Math.Tan(Math.PI / 4 + destination.Latitude / 2);
            var tOrigin      = Math.Tan(Math.PI / 4 + origin.Latitude / 2);

            var dPhi = Math.Log(tDestination / tOrigin);    // E-W line gives dPhi=0
            var q    = (IsFinite(dLat / dPhi)) ? dLat / dPhi : Math.Cos(origin.Latitude);

            // if dLon over 180° take shorter Rhumb across anti-meridian:
            if (Math.Abs(dLon) > Math.PI)
            {
                dLon = dLon > 0 ? -(2 * Math.PI - dLon) : (2 * Math.PI + dLon);
            }

            var distance = Math.Sqrt(dLat * dLat + q * q * dLon * dLon) * radius;
            var bearing  = Math.Atan2(dLon, dPhi);

            return(new GeoRhumb {
                Distance = distance, Bearing = bearing.ToDegreesNormalized()
            });
        }
Example #3
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));
        }
Example #4
0
        /// <summary>
        /// Attempts to calculate approx 1.3M edges when the threshold is a distance from origin in the ball model.
        /// This works for honeycombs with finite cells.
        /// </summary>
        public static Edge[] CalcEdgesSmart(Sphere[] simplex, Edge[] edges, int desiredCount)
        {
            Settings s = new Settings();

            s.ThreshType = EdgeThreshType.Radial;

            // The number of cells increase exponentially with hyperbolic distance,
            // so linear on a log scale.
            // We'll do to test runs to get the line, then run at the extrapolated value.
            double hDist = 5;

            s.Threshold = DonHatch.h2eNorm(hDist);
            Edge[] result = CalcEdges(simplex, edges, s);
            int    count1 = result.Length;

            hDist       = 5.5;
            s.Threshold = DonHatch.h2eNorm(hDist);
            result      = CalcEdges(simplex, edges, s);
            int count2 = result.Length;

            double slope           = (Math.Log(count2) - Math.Log(count1)) / 0.5;
            double logDesiredCount = Math.Log(desiredCount);

            hDist = 5.5 + (logDesiredCount - Math.Log(count2)) / slope;

            s.Threshold = DonHatch.h2eNorm(hDist);
            return(CalcEdges(simplex, edges, s));
        }
Example #5
0
        public static Vector3D SpiralToIsometric(Vector3D v, int p, int m, int n)
        {
            Complex vc = v.ToComplex();

            v = new Vector3D(Math.Log(vc.Magnitude), vc.Phase);

            Vector3D e1 = new Vector3D(0, 1);
            Vector3D e2;

            switch (p)
            {
            case 3:
                e2 = new Vector3D(); break;

            case 4:
                e2 = new Vector3D(); break;

            case 6:
                e2 = new Vector3D(); break;

            default:
                throw new System.ArgumentException();
            }

            double scale = Math.Sqrt(m * m + n * n);
            double a     = Euclidean2D.AngleToClock(new Vector3D(0, 1), new Vector3D(m, n));

            v.RotateXY(a);          // Rotate
            v *= scale;             // Scale

            v *= Math.Sqrt(2) * Geometry2D.EuclideanHypotenuse / (2 * Math.PI);
            v.RotateXY(Math.PI / 4);
            return(v);
        }
Example #6
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 #7
0
        // Box-Muller Transformation
        private float GetRandomPosX(float seedX)
        {
            double x1 = Random.value;
            double x2 = Random.value;

            float posX = (float)(_dispersion * Math.Sqrt(-2 * Math.Log(x1)) * Math.Cos(2 * Math.PI * x2) + seedX);

            if (!_spawnArea.IsInRange(posX))
            {
                posX = _spawnArea.Adjust(posX);
            }

            return(posX);
        }
Example #8
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 #9
0
        private static int Math_Log(ILuaState lua)
        {
            double x = lua.L_CheckNumber(1);
            double res;

            if (lua.IsNoneOrNil(2))
            {
                res = Math.Log(x);
            }
            else
            {
                double logBase = lua.L_CheckNumber(2);
                if (logBase == 10.0)
                {
                    res = Math.Log10(x);
                }
                else
                {
                    res = Math.Log(x, logBase);
                }
            }
            lua.PushNumber(res);
            return(1);
        }
Example #10
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 #11
0
 /// <summary>
 /// Handles the calculation for inverse hyperbolic cosine.
 /// </summary>
 /// <param name="x">A double to be evaluated.</param>
 /// <returns>Returns the inverse hyperbolic cosine of a number.</returns>
 public static double InverseHyperbolicCosine(double x)
 {
     return(MathObj.Log(x + MathObj.Sqrt(x * x - 1)));
 }
Example #12
0
 /// <summary>
 /// Handles the calculation for inverse hyperbolic cotangent.
 /// </summary>
 /// <param name="x">A double to be evaluated.</param>
 /// <returns>Returns the inverse hyperbolic cotangent of a number.</returns>
 public static double InverseHyperbolicCotangent(double x)
 {
     return(MathObj.Log((x + 1.0) / (x - 1.0)) / 2.0);
 }
Example #13
0
 /// <summary>
 /// Handles the calculation for Inverse Hyperbolic Tangent.
 /// </summary>
 /// <param name="x">A double to be evaluated.</param>
 /// <returns>Returns the inverse hyperbolic tangent of a number.</returns>
 public static double InverseHyperbolicTangent(double x)
 {
     return(MathObj.Log((1 + x) / (1 - x)) / 2);
 }
Example #14
0
 // Inverse Hyperbolic Tangent
 public static double HArctan(double x)
 {
     return(MathObj.Log((1 + x) / (1 - x)) / 2);
 }
Example #15
0
        log1p(double x)
        {
            double u = 1.0 + x;

            return(Math.Log(u) - ((u - 1.0) - x) / u);
        }
Example #16
0
 public static double Log(object self, double x)
 {
     return(DomainCheck(SM.Log(x), "log"));
 }
Example #17
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="c">Kamera g³ówna</param>
        /// <param name="playerPlane">Obiekt samolotu gracza (model)</param>
        /// <param name="evt">FrameEvent (chodzi o czas od ostatniej klatki)</param>
        /// <param name="manualZoom"></param>
        /// <returns></returns>
        public static void Manage(Camera c, Plane playerPlane, FrameEvent evt, float manualZoom)
        {
            Plane p = null;

            if (playerPlane != null)
            {
                p = playerPlane;
            }
            Vector3 translateVector = Vector3.ZERO;

            float t = evt.timeSinceLastFrame;

            if (t >= 1.0f)
            {
                t = 0.99f;
            }

            float minCamDistance = 15;
            float halfMaxHeight  = (float)GameConsts.GenericPlane.CurrentUserPlane.MaxHeight / 2.0f;

            float realHalfMaxHeight = halfMaxHeight * 0.95f;
            float camAlt            = c.RealPosition.y + c.Position.y;
            // float camAlt = c.RealPosition.y;

            float minCamAlt = 4.0f;


            /* bool duringEmergency = false;
             *
             * // awaryjne wynurzenie kamery;)
             * if (c._getDerivedPosition().y + c.Position.y <= 0)
             * {
             *   // metr nad wod¹
             *   Vector3 emergency = new Vector3(0, c.Position.y + c._getDerivedPosition().y + 1.0f, 0);
             *   c.MoveRelative(emergency);
             *   duringEmergency = true;
             * }*/


            // wysokosc
            if (camAlt < minCamAlt)
            {
                translateVector.y = 40 * (minCamAlt - camAlt); // wynurzenie kamery znad powierchni wody
            }
            else if (camAlt > 10)
            {
                // powrot w ozi Y
                if (c.Position.y > 0.01f && EngineConfig.CurrentGameSpeedMultiplier != EngineConfig.GameSpeedMultiplierSlow)
                {
                    translateVector.y = -(c.Position.y) / 10.0f;
                }
            }


            // ZOOMING
            float speed       = (float)p.Speed;
            float speedFactor = 0;
            float altFactor   = 0;

            // wspolczynnik wysokosci
            if (c.RealPosition.y > 0)
            {
                altFactor = (float)Math.Log(c.RealPosition.y + 1, 1.011);
                altFactor = Math.Max(0, altFactor);
            }
            float zoomFactor;

            speedFactor = speed; // wsp. szybkosci

            //altFactor*=altFactor * altFactor;
            if (playerPlane.Position.Y < 30)
            {
                altFactor /= (30 - (float)playerPlane.Position.Y) * 0.15f;
            }
            if (altFactor > 250)
            {
                altFactor = 250;
            }
            zoomFactor = speedFactor * 0.1f + altFactor * 0.53f + (-manualZoom + minCamDistance - c.Position.z);

            // Bullet-time
            if (EngineConfig.CurrentGameSpeedMultiplier == EngineConfig.GameSpeedMultiplierSlow)
            {
                zoomFactor += -manualZoom + minCamDistance - c.Position.z + 30.0f;
            }

            translateVector.z += zoomFactor;



            // ruch kamery w zaleznosci od wysokosci
            if (c.RealPosition.y >= realHalfMaxHeight && EngineConfig.CurrentGameSpeedMultiplier != EngineConfig.GameSpeedMultiplierSlow)
            {
                translateVector.y -= (camAlt - realHalfMaxHeight);
            }
            else if (c.RealPosition.y < (realHalfMaxHeight * 0.75f))
            {
                if (c.Position.y < 0)
                {
                    translateVector.y -= c.Position.y;
                }
            }



            // ograniczenia awaryjne
            // translateVector.z += manualZoom;

            translateVector.x = Math.Min(translateVector.x, 500);
            translateVector.y = Math.Min(translateVector.y, 500);
            translateVector.z = Math.Min(translateVector.z, 500);

            translateVector.x = Math.Max(translateVector.x, -500);
            translateVector.y = Math.Max(translateVector.y, -500);
            translateVector.z = Math.Max(translateVector.z, -500);


            // uzaleznij od czasu
            translateVector *= t;
            c.MoveRelative(translateVector);
        }
Example #18
0
 // Inverse Hyperbolic Secant
 public static double HArcsec(double x)
 {
     return(MathObj.Log((MathObj.Sqrt(-x * x + 1) + 1) / x));
 }
Example #19
0
 // Inverse Hyperbolic Cotangent
 public static double HArccotan(double x)
 {
     return(MathObj.Log((x + 1) / (x - 1)) / 2);
 }
Example #20
0
 // Inverse Hyperbolic Cosecant
 public static double HArccosec(double x)
 {
     return(MathObj.Log((MathObj.Sign(x) * MathObj.Sqrt(x * x + 1) + 1) / x));
 }
Example #21
0
 // Inverse Hyperbolic Cosine
 public static double HArccos(double x)
 {
     return(MathObj.Log(x + MathObj.Sqrt(x * x - 1)));
 }
Example #22
0
 // Logarithm to base N
 public static double LogN(double x, double n)
 {
     return(MathObj.Log(x) / MathObj.Log(n));
 }
Example #23
0
 public static double Asinh(object self, double x)
 {
     //ln(x + sqrt(x*x + 1))
     return(SM.Log(x + SM.Sqrt(x * x + 1)));
 }
Example #24
0
 public static double Atanh(object self, double x)
 {
     //(1/2) * ln((1+x)/(1-x))
     return(DomainCheck((1 / 2) * SM.Log((1 + x) / (1 - x)), "atanh"));
 }
Example #25
0
 public static double Log2(object self, [DefaultProtocol] double x)
 {
     return(DomainCheck(SM.Log(x) / SM.Log(2), "log2"));
 }
Example #26
0
 public static double Acosh(object self, [DefaultProtocol] double x)
 {
     //ln(x + sqrt(x*x - 1)) for x >= 1
     return(DomainCheck(SM.Log(x + SM.Sqrt(x * x - 1)), "acosh"));
 }
Example #27
0
 acosh(double x)
 {
     return(2 * Math.Log(Math.Sqrt((x + 1) * .5) + Math.Sqrt((x - 1) * .5)));
 }
Example #28
0
 public static double Asinh(object self, [DefaultProtocol] double x)
 {
     //ln(x + sqrt(x*x + 1))
     return(SM.Log(x + SM.Sqrt(x * x + 1)));
 }
Example #29
0
 public static double Atanh(object self, [DefaultProtocol] double x)
 {
     //(1/2) * ln((1+x)/(1-x))
     return(DomainCheck(0.5 * SM.Log((1 + x) / (1 - x)), "atanh"));
 }
Example #30
0
 // Inverse Hyperbolic Sine
 public static double HArcsin(double x)
 {
     return(MathObj.Log(x + MathObj.Sqrt(x * x + 1)));
 }