Beispiel #1
0
        /// <summary>
        /// Mirrors across line through line segment. Returns a new matrix with the result.
        /// </summary>
        /// <param name="l">The across which to mirror.</param>
        public Transform2D Mirror(LineSeg2D l)
        {
            // See here: http://planetmath.org/encyclopedia/DerivationOf2DReflectionMatrix.html


            // Mirror around origin
            //
            //         0           1       2
            // 0   x^2 - y^2      2xy      0
            // 1      2xy      y^2 - x^2   0
            // 2       0           0       1

            var v      = l.GetVectorP1toP2().Normalize();
            var mirror = new Transform2D(
                new[, ]
            {
                { DecimalEx.Pow(v.X, 2) - DecimalEx.Pow(v.Y, 2), 2 * v.X * v.Y, 0 },
                { 2 * v.X * v.Y, DecimalEx.Pow(v.Y, 2) - DecimalEx.Pow(v.X, 2), 0 },
                { 0, 0, 1 }
            });

            // Translate to origin because mirroring around a vector is relative to the origin.
            var r = Translate(-l.Pt1.X, -l.Pt1.Y);

            // Left multiply this transformation matrix
            r = mirror.Multiply(r);

            // Translate back where we came from
            r = r.Translate(l.Pt1.X, l.Pt1.Y);

            return(r);
        }
Beispiel #2
0
 public Term Pow(decimal power)
 {
     var fundamental = ConvertUnitToFundamental();
     var resMagnitude = DecimalEx.Pow(fundamental.Magnitude, power);
     var resQuantity = fundamental.Quantity.Pow(power);
     return new(resMagnitude, resQuantity.FundamentalUnit);
 }
Beispiel #3
0
        static Prefixes()
        {
            Yotta = new("yotta", 1e24m, "Y");
            Zetta = new("zetta", 1e21m, "Z");
            Exa   = new("exa", 1e18m, "E");
            Peta  = new("peta", 1e15m, "P");
            Tera  = new("tera", 1e12m, "T");
            Giga  = new("giga", 1e9m, "G");
            Mega  = new("mega", 1e6m, "M");
            Kilo  = new("kilo", 1e3m, "k");
            Hecto = new("hecto", 1e2m, "h");
            Deca  = new("deca", 1e1m, "da");

            Deci  = new("deci", 1e-1m, "d");
            Centi = new("centi", 1e-2m, "c");
            Milli = new("milli", 1e-3m, "m");
            Micro = new("micro", 1e-6m, "μ");
            Nano  = new("nano", 1e-9m, "n");
            Pico  = new("pico", 1e-12m, "p");
            Femto = new("femto", 1e-15m, "f");
            Atto  = new("atto", 1e-18m, "a");
            Zepto = new("zepto", 1e-21m, "z");
            Yocto = new("yocto", 1e-24m, "y");

            Kibi = new("kibi", DecimalEx.Pow(2m, 10m), "Ki");
            Mebi = new("mebi", DecimalEx.Pow(2m, 20m), "Mi");
            Gibi = new("gibi", DecimalEx.Pow(2m, 30m), "Gi");
            Tebi = new("tebi", DecimalEx.Pow(2m, 40m), "Ti");
            Pebi = new("pebi", DecimalEx.Pow(2m, 50m), "Pi");
            Exbi = new("exbi", DecimalEx.Pow(2m, 60m), "Ei");
        }
        public static decimal Pow(this decimal value, decimal other)
        {
            if (value.IsNaN() || other.IsNaN())
            {
                return(Decimals.NaN);
            }

            return(DecimalEx.Pow(value, other));
        }
Beispiel #5
0
        public async Task <decimal> CalcularMontanteAsync(decimal valorInicial, int tempo)
        {
            await BuscarTaxa();

            decimal calc1      = DecimalEx.Pow((1 + juros), tempo) * valorInicial;
            decimal valorFinal = Truncar(calc1);

            return(valorFinal);
        }
Beispiel #6
0
        private void CalculateWindChill()
        {
            var temperatureInF = Temperature;
            var windSpeedInMph = WindSpeed;

            if (temperatureInF.IsBetween(-45, 45) && windSpeedInMph.IsBetween(3, 60))
            {
                WindChill = 35.74m + 0.6215m * temperatureInF - 35.75m * DecimalEx.Pow(windSpeedInMph, 0.16m) + 0.4275m * temperatureInF * DecimalEx.Pow(windSpeedInMph, 0.16m);
            }
        }
Beispiel #7
0
        public decimal Calcular()
        {
            if (!IsValid())
            {
                return(0);
            }

            var jurosElevadoAoTempo = DecimalEx.Pow(1 + TaxaJuros, Tempo);

            return((ValorInicial * jurosElevadoAoTempo).Truncate(2));
        }
Beispiel #8
0
        // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
        // Inverse Gamma 709 RGB -> RGB
        // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
        static decimal[] inverse_gamma_709(ref decimal[] nonlinear_rgb709)
        {
            decimal[] linear_rgb709 = new decimal[3] {
                0, 0, 0
            };
            for (int i = 0; i < 3; i++)
            {
                linear_rgb709[i] = DecimalEx.Pow(Math.Abs(nonlinear_rgb709[i]), (decimal)2.4);
            }

            return(linear_rgb709);
        }
Beispiel #9
0
        // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
        // Linear 2020 To NonLinear 2020
        // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
        static decimal[] Inverse_gamma_2020(ref decimal[] linear_rgb2020)
        {
            decimal[] nonlinear_rgb2020 = new decimal[3] {
                0, 0, 0
            };
            for (int i = 0; i < 3; i++)
            {
                nonlinear_rgb2020[i] = DecimalEx.Pow(Math.Abs(linear_rgb2020[i]), (decimal)(1 / 2.4));
            }

            return(nonlinear_rgb2020);
        }
Beispiel #10
0
        public static BigIntegerRactional ConvertToRactional(decimal n)
        {
            var ndec = GetNumOfDecimals(n);

            if (ndec == 0)
            {
                return(BigIntegerRactional.Create((BigInteger)n));
            }

            var n2 = DecimalEx.Pow(10, ndec);

            return(BigIntegerRactional.Create((BigInteger)(n * n2), (BigInteger)n2));
        }
Beispiel #11
0
        // for defining from a chain of operations
        protected Unit(string name, NamedComposition <IUnit> composition)
            : base(name)
        {
            // TODO: notify user that offsets will be ignored
            //var offsetQuery =
            //    from baseUnit in composition.Composition.Keys
            //    where baseUnit.FundamentalOffset != 0m
            //    select baseUnit;

            UnitComposition       = composition;
            Quantity              = Quantity.GetFromBaseComposition(UnitComposition);
            FundamentalMultiplier = 1m;
            FundamentalOffset     = 0;
            foreach (var(unit, power) in UnitComposition.Composition)
            {
                var multiplier = DecimalEx.Pow(unit.FundamentalMultiplier, power);
                FundamentalMultiplier *= multiplier;
            }
        }
Beispiel #12
0
        public decimal CalculaJuros(decimal valorInicial, int tempo, decimal juros)
        {
            decimal valorFinal = Truncar(DecimalEx.Pow((1 + juros), tempo) * valorInicial);

            return(valorFinal);
        }
Beispiel #13
0
 public void NegativeExponentOfZero()
 {
     Assert.Throws <OverflowException>(() => DecimalEx.Pow(0, -1));
 }
Beispiel #14
0
 public void Test(decimal x, decimal y, decimal expected, decimal tolerance)
 {
     tolerance = Helper.GetScaledTolerance(expected, (int)tolerance, true);
     Debug.WriteLine("Pow({0}, {1}) = {2} within {3} (is {4})", x, y, DecimalEx.Pow(x, y), tolerance, DecimalEx.Pow(x, y) - expected);
     Assert.That(DecimalEx.Pow(x, y), Is.EqualTo(expected).Within(tolerance));
 }
Beispiel #15
0
        public async Task <decimal> Calcular()
        {
            var Potenciacao = (DecimalEx.Pow(1 + TaxaJuros, Tempo));

            return(DecimalHelpers.Truncate(ValorInicial * Potenciacao, 2));
        }
Beispiel #16
0
 public static decimal Truncate(this decimal value, int decimalPlaces)
 {
     return(decimal.Truncate(value * DecimalEx.Pow(10, decimalPlaces)) / DecimalEx.Pow(10, decimalPlaces));
 }
        public void UpdateFilter()
        {
            var     A             = DecimalEx.Pow(10, Gain / 40m);
            var     w             = DecimalEx.TwoPi * Frequency / SampleRate;
            var     cosw          = DecimalEx.Cos(w);
            var     sinw          = DecimalEx.Sin(w);
            var     alpha         = sinw / (2 * Q);
            var     Am1cosw       = (A - 1m) * cosw;
            var     Ap1cosw       = (A + 1m) * cosw;
            var     TwoSqrtAalpha = 2m * DecimalEx.Sqrt(A) * alpha;
            decimal a0            = 1m;

            switch (Type)
            {
            case FilterType.Disabled:
                b0    = 1;
                b1    = b2 = a1 = a2 = 0;
                FP_b0 = 0x00800000;
                FP_b1 = FP_b2 = FP_a1 = FP_a2 = 0;
                return;

            case FilterType.EQ:
                b0 = 1m + alpha * A;
                b1 = a1 = -2m * cosw;
                b2 = 1m - alpha * A;
                a0 = 1m + alpha / A;
                a2 = 1m - alpha / A;
                break;

            case FilterType.Lowpass:
                b1 = 1m - cosw;
                b2 = b0 = b1 / 2m;
                a0 = 1m + alpha;
                a1 = -2m * cosw;
                a2 = 1m - alpha;
                break;

            case FilterType.Highpass:
                b1 = -1m - cosw;
                b0 = b2 = -b1 / 2m;
                a0 = 1m + alpha;
                a1 = -2m * cosw;
                a2 = 1m - alpha;
                break;

            case FilterType.Bandpass:
                b0 = alpha;
                b1 = 0;
                b2 = -alpha;
                a0 = 1m + alpha;
                a1 = -2m * cosw;
                a2 = 1m - alpha;
                break;

            case FilterType.Notch:
                b0 = b2 = 1m;
                a0 = 1m + alpha;
                a1 = b1 = -2m * cosw;
                a2 = 1m - alpha;
                break;

            case FilterType.LowShelf:
                b0 = A * (A + 1m - Am1cosw + TwoSqrtAalpha);
                b1 = 2m * A * (A - 1m - Ap1cosw);
                b2 = A * (A + 1m - Am1cosw - TwoSqrtAalpha);
                a0 = A + 1m + Am1cosw + TwoSqrtAalpha;
                a1 = -2m * (A - 1m + Ap1cosw);
                a2 = A + 1m + Am1cosw - TwoSqrtAalpha;
                break;

            case FilterType.HighShelf:
                b0 = A * (A + 1m + Am1cosw + TwoSqrtAalpha);
                b1 = -2m * A * (A - 1m + Ap1cosw);
                b2 = A * (A + 1m + Am1cosw - TwoSqrtAalpha);
                a0 = A + 1m - Am1cosw + TwoSqrtAalpha;
                a1 = 2m * (A - 1m - Ap1cosw);
                a2 = A + 1m - Am1cosw - TwoSqrtAalpha;
                break;

            case FilterType.Custom:
                break;
            }
            b0 /= a0;
            b1 /= a0;
            b2 /= a0;
            a1 /= a0;
            a2 /= a0;
            if (NegateA && Type != FilterType.Custom)
            {
                a1 *= -1m;
                a2 *= -1m;
            }
            FP_b0 = ToFP(b0);
            FP_b1 = ToFP(b1);
            FP_b2 = ToFP(b2);
            FP_a1 = ToFP(a1);
            FP_a2 = ToFP(a2);
            b0    = FromFP(FP_b0);
            b1    = FromFP(FP_b1);
            b2    = FromFP(FP_b2);
            a1    = FromFP(FP_a1);
            a2    = FromFP(FP_a2);
        }