Пример #1
0
        public override Vector2 <decimal> EquatorialCoordinates(DateTime date)
        {
            var pos = EclipticEarth3D(date);

#if DEBUG
            Console.WriteLine($"Sun ecliptic position: X={pos.X} Y={pos.Y} Z={pos.Z}");
#endif

            var tiltRad = CommonCalculations.GetAxialTilt(date) * DecimalMath.DegToRad;
            var Xe      = pos.X;
            var Ye      = pos.Y * DecimalMath.Cos(tiltRad);
            var Ze      = pos.Y * DecimalMath.Sin(tiltRad);

#if DEBUG
            Console.WriteLine($"Sun equatorial position: X={Xe} Y={Ye} Z={Ze} with tilt {tiltRad}");
#endif

            var RA  = DecimalMath.Atan2(Ye, Xe) * DecimalMath.RadToDeg;
            var Dec = DecimalMath.Atan2(Ze, DecimalMath.Sqrt(Xe * Xe + Ye * Ye)) * DecimalMath.RadToDeg;

#if DEBUG
            Console.WriteLine($"Sun RA = {RA} Dec={Dec}");
#endif
            return(new Vector2 <decimal>(CommonCalculations.From0To360(RA), Dec));
        }
Пример #2
0
        public override Vector2 <decimal> EquatorialCoordinates(DateTime date)
        {
            var pos = EclipticEarth3D(date);
            var X = pos.X; var Y = pos.Y; var Z = pos.Z;
            var R         = DecimalMath.Sqrt(X * X + Y * Y + Z * Z);
            var lambda    = DecimalMath.Atan2(Y, X);
            var sinLambda = DecimalMath.Sin(lambda);
            var cosLambda = DecimalMath.Cos(lambda);
            var beta      = DecimalMath.Asin(Z / R);
            var tanBeta   = DecimalMath.Tan(beta);
            var sinBeta   = DecimalMath.Sin(beta);
            var cosBeta   = DecimalMath.Cos(beta);

            var tilt    = CommonCalculations.GetAxialTilt(date) * DecimalMath.DegToRad;
            var cosTilt = DecimalMath.Cos(tilt);
            var sinTilt = DecimalMath.Sin(tilt);
            var RA      = DecimalMath.Atan2(sinLambda * cosTilt - tanBeta * sinTilt, cosLambda) * DecimalMath.RadToDeg;
            var Dec     = DecimalMath.Asin(sinBeta * cosTilt + cosBeta * sinTilt * sinLambda) * DecimalMath.RadToDeg;

            RA = CommonCalculations.From0To360(RA);
#if DEBUG
            Console.WriteLine($"R = {R} lambda = {lambda}, beta = {beta}, tilt = {tilt}, RA = {RA}, dec = {Dec}");
#endif

            return(new Vector2 <decimal>(RA, Dec));
        }
Пример #3
0
        public override Vector2 <decimal> EclipticCoordinates(DateTime date)
        {
            var pos = EclipticEarth3D(date);
            var lon = DecimalMath.Atan2(pos.Y, pos.X) * DecimalMath.RadToDeg;
            var lat = DecimalMath.Asin(pos.Z / DecimalMath.Sqrt(pos.X * pos.X + pos.Y * pos.Y + pos.Z * pos.Z)) * DecimalMath.RadToDeg;

            return(new Vector2 <decimal>(CommonCalculations.From0To360(lon), lat));
        }
Пример #4
0
 public decimal GetValue(decimal from0To1)
 {
     if (from0To1 < eps)
     {
         return(0m);
     }
     return(DecimalMath.Sqrt(from0To1));
 }
Пример #5
0
        public void Sqrt()
        {
            const decimal expected = 9.0M;
            decimal       actual   = 81.0M;

            actual = DecimalMath.Sqrt(actual);
            Assert.AreEqual <decimal>(expected, actual);
        }
Пример #6
0
        public override Vector2 <decimal> ApparentEclipticEarth(DateTime date)
        {
            var pos = ApparentEclipticEarth3D(date);
            var lon = DecimalMath.Atan2(pos.Y, pos.X) * DecimalMath.RadToDeg;
            var lat = DecimalMath.Asin(pos.Z / DecimalMath.Sqrt(pos.X * pos.X + pos.Y * pos.Y + pos.Z * pos.Z)) * DecimalMath.RadToDeg;

            lon = CommonCalculations.From0To360(lon);
            lat = CommonCalculations.From0To360(lat);
            return(new Vector2 <decimal>(lon, lat));
        }
Пример #7
0
        public void TanSqrt3()
        {
            const decimal THREE    = 3.0M;
            decimal       expected = DecimalMath.Sqrt(THREE);
            decimal       actual   = DecimalMath.PI / THREE;

            actual = DecimalMath.Tan(actual);

            expected = Math.Round(expected, 22);    //1.7320508075688772935274463415
            actual   = Math.Round(actual, 22);      //1.7320508075688772935274463414

            Assert.AreEqual <decimal>(expected, actual);
        }
Пример #8
0
        public Vector2 <decimal> EquatorialCoordinates(DateTime date)
        {
            var tilt    = CommonCalculations.GetAxialTilt(date) * DecimalMath.DegToRad;
            var sintilt = DecimalMath.Sin(tilt);
            var costilt = DecimalMath.Cos(tilt);

            var pos = EclipticEarthXYZ(date);
            var xe  = pos.X;
            var ye  = pos.Y * costilt - pos.Z * sintilt;
            var ze  = pos.Y * sintilt - pos.Z * costilt;

#if DEBUG
            Console.WriteLine($"Pluto equatorial X= {xe}, Y = {ye}, Z = {ze}");
#endif

            var RA  = DecimalMath.Atan2(ye, xe) * DecimalMath.RadToDeg;
            var Dec = DecimalMath.Atan2(ze, DecimalMath.Sqrt(xe * xe, ye * ye)) * DecimalMath.RadToDeg;

#if DEBUG
            Console.WriteLine($"Pluto Ra= {RA}, DEC = {Dec}");
#endif
            return(new Vector2 <decimal>(CommonCalculations.From0To360(RA), Dec));
        }
Пример #9
0
 public void SquareRoot(decimal number)
 {
     DecimalMath.Sqrt(number);
 }
Пример #10
0
        public override Vector3 <decimal> EclipticSun3D(DateTime date)
        {
            var degToRad = DecimalMath.Pi / 180;

            var days = JulianDateCalculator.ToJulianDaysJ2000(date);

            var M    = MeanAnomaly(days);
            var MRad = M * degToRad;
            var e    = Eccentricity(days);

#if DEBUG
            Console.WriteLine($"Days = {days} Mean Anomaly={M} Eccentricity = {e}");
#endif

            var sinM  = DecimalMath.Sin(MRad);
            var sin2M = DecimalMath.Sin(2 * MRad);
            var sin3M = DecimalMath.Sin(3 * MRad);
            var sin4M = DecimalMath.Sin(4 * MRad);
            var sin5M = DecimalMath.Sin(5 * MRad);
            var sin6M = DecimalMath.Sin(6 * MRad);
            var e2    = DecimalMath.Power(e, 2);
            var e3    = DecimalMath.Power(e, 3);
            var e4    = DecimalMath.Power(e, 4);
            var e5    = DecimalMath.Power(e, 5);
            var e6    = DecimalMath.Power(e, 6);

            var eccentricAnomalyRad =
                MRad
                + e * sinM
                + e2 * 0.5m * sin2M
                + e3 * (0.375m * sin3M - 0.125m * sinM)
                + e4 * (-(1m / 6m) * sin2M + (1m / 3m) * sin4M)
                + e5 * (-(27m / 128m) * sin3M + (1m / 192m) * sinM + (125m / 384m) * sin5M)
                + e6 * ((1m / 48m) * sin2M + (27 / 80) * sin6M - (4 / 15) * sin4M);

#if DEBUG
            Console.WriteLine($"Eccentric Anomaly {eccentricAnomalyRad * DecimalMath.RadToDeg}");
#endif

            // Calculate true anomaly
            var A  = SemimajorAxis(days);
            var Xv = A * (DecimalMath.Cos(eccentricAnomalyRad) - e);
            var Yv = A * DecimalMath.Sqrt(1.0m - e * e) * DecimalMath.Sin(eccentricAnomalyRad);

            var v = DecimalMath.Atan2(Yv, Xv);
            var r = DecimalMath.Sqrt(Xv * Xv + Yv * Yv);

            //Calculate Heliocentric coordinates
            var N     = LongAscedingNode(days) * degToRad;
            var cosN  = DecimalMath.Cos(N);
            var sinN  = DecimalMath.Sin(N);
            var i     = Inclination(days) * degToRad;
            var cosi  = DecimalMath.Cos(i);
            var sini  = DecimalMath.Sin(i);
            var w     = Peryhelion(days) * degToRad;
            var cosVW = DecimalMath.Cos(v + w);
            var sinVW = DecimalMath.Sin(v + w);

#if DEBUG
            Console.WriteLine($"LongAscNode : {LongAscedingNode(days)}, Inclination : {Inclination(days)}");
            Console.WriteLine($"Peryhelion: {Peryhelion(days)} true anomaly : {DecimalMath.Atan2(Yv, Xv) * DecimalMath.RadToDeg}");
#endif

            var Xh = r * (cosN * cosVW - sinN * sinVW * cosi);
            var Yh = r * (sinN * cosVW + cosN * sinVW * cosi);
            var Zh = r * (sinVW * sini);

#if DEBUG
            Console.WriteLine($"{Name} heliocentric coordinates {Xh} {Yh} {Zh}");
#endif

            return(new Vector3 <decimal>(Xh, Yh, Zh));
        }
Пример #11
0
        public decimal calculate(Queue <string> polska, decimal x)
        {
            decimal answer = 0;

            Stack <decimal> opers = new Stack <decimal>();

            foreach (string s in polska)
            {
                if (standartOperators.Contains(s))
                {
                    decimal a;
                    decimal b;

                    switch (s)
                    {
                    case "+":
                        opers.Push(opers.Pop() + opers.Pop());
                        break;

                    case "-":
                        b = opers.Pop();
                        a = opers.Pop();
                        opers.Push(a - b);
                        break;

                    case "*":
                        opers.Push(opers.Pop() * opers.Pop());
                        break;

                    case "/":
                        b = opers.Pop();
                        a = opers.Pop();
                        opers.Push(a / b);
                        break;

                    case "^":
                        b = opers.Pop();
                        a = opers.Pop();
                        opers.Push(DecimalMath.Pow(a, b));
                        break;

                    case "%":
                        b = opers.Pop();
                        a = opers.Pop();
                        opers.Push(a % b);
                        break;

                    case "sqrt":
                        opers.Push(DecimalMath.Sqrt(opers.Pop()));
                        break;

                    case "sin":
                        opers.Push(DecimalMath.Sin(opers.Pop()));
                        break;

                    case "cos":
                        opers.Push(DecimalMath.Cos(opers.Pop()));
                        break;

                    case "tan":
                        opers.Push(DecimalMath.Tan(opers.Pop()));
                        break;

                    case "atan":
                        opers.Push(DecimalMath.Atan(opers.Pop()));
                        break;

                    case "acos":
                        opers.Push(DecimalMath.Acos(opers.Pop()));
                        break;

                    case "asin":
                        opers.Push(DecimalMath.Asin(opers.Pop()));
                        break;

                    case "acotan":
                        opers.Push(DecimalMath.Atan(1 / opers.Pop()));
                        break;

                    case "exp":
                        opers.Push(DecimalMath.Exp(opers.Pop()));
                        break;

                    case "log":
                        opers.Push(DecimalMath.Log(opers.Pop()));
                        break;

                    case "ln":
                        opers.Push(DecimalMath.Log10(opers.Pop()));
                        break;

                    case "sinh":
                        opers.Push(DecimalMath.Sinh(opers.Pop()));
                        break;

                    case "cosh":
                        opers.Push(DecimalMath.Cosh(opers.Pop()));
                        break;

                    case "tanh":
                        opers.Push(DecimalMath.Tanh(opers.Pop()));
                        break;

                    case "abs":
                        opers.Push(DecimalMath.Abs(opers.Pop()));
                        break;

                    case "ceil":
                        opers.Push(DecimalMath.Ceiling(opers.Pop()));
                        break;

                    case "floor":
                        opers.Push(DecimalMath.Floor(opers.Pop()));
                        break;

                    case "fac":
                        opers.Push(factorial(opers.Pop()));
                        break;

                    case "sfac":
                        opers.Push(semifactorial(opers.Pop()));
                        break;

                    case "round":
                        opers.Push(DecimalMath.Round(opers.Pop()));
                        break;

                    case "fpart":
                        a = opers.Pop();
                        opers.Push(a - DecimalMath.Truncate(a));
                        break;
                    }
                }
                else if (s == "x")
                {
                    opers.Push(x);
                }
                else
                {
                    opers.Push(decimal.Parse(s));
                }
            }

            answer = opers.Pop();
            return(answer);
        }
Пример #12
0
 /// <summary>
 /// Returns distances between two decimal Vector2 instances
 /// </summary>
 /// <param name="V1"></param>
 /// <param name="V2"></param>
 /// <returns></returns>
 public static decimal Distance(Vector2 <decimal> V1, Vector2 <decimal> V2)
 {
     return(DecimalMath.Sqrt(DecimalMath.Power(V1.X - V2.X, 2) + DecimalMath.Power(V1.Y - V2.Y, 2)));
 }
Пример #13
0
 /// <summary>
 /// Calculate Euclidean metric for 3D points
 /// </summary>
 /// <param name="v1"></param>
 /// <param name="v2"></param>
 /// <returns></returns>
 public static decimal Distance(Vector3 <decimal> v1, Vector3 <decimal> v2)
 {
     return(DecimalMath.Sqrt(DecimalMath.Power(v1.X - v2.X, 2) + DecimalMath.Power(v1.Y - v2.Y, 2) + DecimalMath.Power(v1.Z - v2.Z, 2)));
 }