Exemple #1
0
        public Curve CalculateCurve(Collider inComingClimber)
        {
            Curve   curve      = new Curve();
            Vector3 firstPoint = inComingClimber.transform.position;
            Vector3 lastPoint  = jumpPoint.position;

            curve.Add(firstPoint);
            float          timing        = 0;
            AnimationCurve jump          = CentralData.Instance.JumpData.JumpCurve;
            float          min           = jump.GetMin();
            float          max           = jump.GetMax();
            float          first         = jump.keys[0].time;
            float          last          = jump.keys[jump.length - 1].time;
            Vector3        flatDirection = (lastPoint - firstPoint);

            flatDirection.y = 0;
            float distance = flatDirection.magnitude;

            flatDirection.Normalize();
            while (timing < last)
            {
                timing += Time.deltaTime;
                float   eval = jump.Evaluate(timing);
                float   x    = eval.Map(first, last, 0, distance);
                float   y    = timing.Map(min, max, firstPoint.y, lastPoint.y);
                Vector3 move = flatDirection * x;
                move.y = y;
                curve.Add(move);
            }
            curve.Add(lastPoint);
            return(curve);
        }
Exemple #2
0
        public void When_ComputeAreaUnderCurve_Square_Expect_Reference()
        {
            // arrange
            var curve = new Curve();

            // act
            curve.Add(new Point(0, 1.0));
            curve.Add(new Point(1, 1.0));

            // assert
            Assert.Equal(1.0, curve.ComputeAreaUnderCurve());
        }
Exemple #3
0
        public void When_Add_Count_Expect_Reference()
        {
            // arrange
            var curve = new Curve();

            // act
            curve.Add(new Point(0, 0.5));
            curve.Add(new Point(0, 0.1));
            curve.Add(new Point(1, 0.2));
            curve.Add(new Point(3, 0.3));

            // assert
            Assert.Equal(4, curve.PointsCount);
        }
        public void When_HigherTriangleCurve_Expect_Reference()
        {
            // arrange
            var triangle = new Curve();

            triangle.Add(new Point(-1.0, 0));
            triangle.Add(new Point(0, 3));
            triangle.Add(new Point(1, 0));

            // act
            var pdfTriangle = new Pdf(triangle);

            // assert
            Assert.Equal(1.0, pdfTriangle.ComputeAreaUnderCurve());
        }
Exemple #5
0
        public void When_Add_Same_Expect_Reference()
        {
            // arrange
            var curve = new Curve();

            // act
            curve.Add(new Point(0, 0.5));
            curve.Add(new Point(0, 0.1));

            // assert
            Assert.Equal(0.5, curve.GetFirstPoint().Y);
            Assert.Equal(0, curve.GetFirstPoint().X);
            Assert.Equal(0.1, curve.GetLastPoint().Y);
            Assert.Equal(0, curve.GetLastPoint().X);
        }
        public void When_ConstPdf_Expect_Reference()
        {
            // arrange
            var curve = new Curve();

            curve.Add(new Point(-1, 0.5));
            curve.Add(new Point(1, 0.5));
            var pdf = new Pdf(curve);

            // act
            var cdf = new Cdf(pdf, 100);

            // assert
            Assert.Equal(100, cdf.PointsCount);
        }
Exemple #7
0
    /// <summary>
    /// modifies a module
    /// </summary>
    /// <returns>The mod.</returns>
    /// <param name="baseMod">Base mod.</param>
    /// <param name="modType">Mod type.</param>
    private static ModuleBase modMod(ModuleBase baseMod, int modType, System.Random rand)
    {
        switch (modType)
        {
        case 0:         //curves
            Curve c = new Curve(baseMod);
            for (int i = 0; i < 4; i++)
            {
                c.Add(rand.NextDouble() * 2 - 1, rand.NextDouble() * 2 - 1);
            }
            return(c);

        case 1:        //terrace
            Terrace terr      = new Terrace(baseMod);
            int     numPoints = rand.Next(1, 10);
            for (int i = 0; i < numPoints; i++)
            {
                terr.Add(randDoub(-1, 1, rand.NextDouble()));
            }
            return(terr);

        case 2:        //add noise
            float      scale        = eDist(1, 10000, rand.NextDouble());
            ModuleBase addedTerrain = getGradientNoise(hnProb, rand.NextDouble(), scale, rand);
            double     amplitude    = eDist(.5, scale / 4, rand.NextDouble());
            addedTerrain = new ScaleBias(amplitude, 0, addedTerrain);
            return(new Add(baseMod, addedTerrain));

        case 3:         //scale module input(stretch it)
            return(new Scale(rand.NextDouble() * 5 + .01, rand.NextDouble() * 5 + .01, rand.NextDouble() * 5 + .01, baseMod));

        default:
            return(new Checker());
        }
    }
    void GenerateOwnBlend()
    {
        ModuleBase perlin  = new Perlin(1, 2, .5, 6, 42, QualityMode.Medium);
        ModuleBase voronoi = new Voronoi(Frequency, Displacement, 42, true);
        //ModuleBase blend = new Add(perlin, voronoi);
        Curve curve = new Curve(perlin);

        foreach (var point in Acurve.keys)
        {
            curve.Add(point.time, point.value);
        }

        //curve.Add(0d, .1d);
        //curve.Add(.5d, .5d);
        //curve.Add(1.9d, .9d);

        var perlinbuilder = new Noise2D(Size, Size / 2, perlin);

        perlinbuilder.GeneratePlanar(_left, _right, _top, _bottom);

        var voronoibuilder = new Noise2D(Size, Size / 2, voronoi);

        voronoibuilder.GeneratePlanar(_left, _right, _top, _bottom);

        var blendbuilder = new Noise2D(Size, Size / 2, curve);

        blendbuilder.GeneratePlanar(_left, _right, _top, _bottom);

        Perlin.material.SetTexture("_BaseMap", perlinbuilder.GetTexture(_gradient));
        Voronoi.material.SetTexture("_BaseMap", voronoibuilder.GetTexture(_gradient));
        Mix.material.SetTexture("_BaseMap", blendbuilder.GetTexture(_gradient));
    }
 public AnimationCurveTpl(T defaultValue, T defaultWeight) :
     this(true)
 {
     KeyframeTpl <T> firstKey  = new KeyframeTpl <T>(0.0f, defaultValue, defaultWeight);
     KeyframeTpl <T> secondKey = new KeyframeTpl <T>(1.0f, defaultValue, defaultWeight);
     Curve.Add(firstKey);
     Curve.Add(secondKey);
 }
 public AnimationCurveTpl(T value0, T inSlope0, T outSlope0, T value1, T inSlope1, T outSlope1, T defaultWeight) :
     this(true)
 {
     KeyframeTpl <T> firstKey  = new KeyframeTpl <T>(0.0f, value0, inSlope0, outSlope0, defaultWeight);
     KeyframeTpl <T> secondKey = new KeyframeTpl <T>(1.0f, value1, inSlope1, outSlope1, defaultWeight);
     Curve.Add(firstKey);
     Curve.Add(secondKey);
 }
        public void apply()
        {
            MyConsole.displayMain($"\n\n Applying {name} ----------------------------------: ");
            MyConsole.displayMain($"\n\n-----iteration : 0");


            // Starting timer to mesure completion time
            timer.start();
            // generate initial solution using greedy randomized construction
            initialSolution = buildSolution();
            // At the beginning, the best is the initial solution
            bestSolution = initialSolution;

            if (initialSolution != null)
            {
                CursorPosition cp = new CursorPosition();
                fitnessCurve.Add(model.fitness(initialSolution), 0);

                for (int i = 1; i < model.getNumOfIterations(); i++)
                {
                    // for display ------------------------------------------------------------------------------------------
                    MyConsole.restCursorPosition(cp);
                    MyConsole.displayMain($"\n\n-----------------------------iteration : {i + 1}/{model.getNumOfIterations()}");
                    MyConsole.display($"-----------------------------constructing solution");
                    // -------------------------------------------------------------------------------------------------------

                    solution = buildSolution();
                    solution = localSearch(solution);
                    // If fitness is improved
                    updateBestSolution(i);
                }

                timer.stop(excelFile);


                MyConsole.displayMain($"\n best solution reached : {model.fitness(bestSolution)}");
                exportFitnessToExcel();
                //saveInitialSolution();
                //saveBestSolution();
            }
            else
            {
                MyConsole.displayError("ERROR : Couldn't find Initial solution. Program breaks ");
            }
        }
Exemple #12
0
        public void AddOne()
        {
            var curve = new Curve <int, int>();
            var a     = new Association <int, int>(11, 32);

            curve.Add(a);
            Assert.IsTrue(curve.Contains(a));
            Assert.IsTrue(curve.Contains(11, 32));
        }
Exemple #13
0
        public void IsEmpty()
        {
            var curve = new Curve <int, int>();

            Assert.IsTrue(curve.IsEmpty);
            curve.Add(3, 2);
            Assert.IsFalse(curve.IsEmpty);
            curve.Clear();
            Assert.IsTrue(curve.IsEmpty);
        }
Exemple #14
0
 private void drawAreaPictureBox_MouseDown(object sender, MouseEventArgs e)
 {
     currentCurve = new Curve();
     currentCurve.Add(new Vector()
     {
         Lat = e.Y, Lon = e.X
     });
     curveBox.curves.Add(currentCurve);
     curveBox.Invalidate();
 }
Exemple #15
0
 // Update is called once per frame
 void Update()
 {
     if (cam.pixelRect.Contains(Input.mousePosition))
     {
         if (Input.GetMouseButtonDown(0))
         {
             Vector3 p = mouseToLocal();
             curve.Add(p, 1.0f);
         }
         if (Input.GetMouseButtonDown(1))
         {
             Vector3 p = mouseToLocal();
             selected = Closest(p, 0.1f);
             if (selected != -1)
             {
                 move = true;
             }
         }
         if (Input.GetMouseButton(1))
         {
             if (move && selected != -1)
             {
                 Vector3 p = mouseToLocal();
                 curve.position [selected] = p;
             }
         }
         if (Input.GetKeyDown(KeyCode.X))
         {
             curve.position.Clear();
         }
         if (Input.GetAxis("Mouse ScrollWheel") < 0)
         {
             Vector3 p      = mouseToLocal();
             int     change = Closest(p, 0.1f);
             if (change != -1)
             {
                 curve.weight [change] *= 0.9f;
             }
         }
         if (Input.GetAxis("Mouse ScrollWheel") > 0)
         {
             Vector3 p      = mouseToLocal();
             int     change = Closest(p, 0.1f);
             if (change != -1)
             {
                 curve.weight [change] *= 1.1f;
             }
         }
     }
     l.Clear();
     l.currentColor = Color.blue;
     l.AddLine(curve.position);
     l.currentColor = Color.red;
     l.AddLine(curve.DrawNurbs());
 }
Exemple #16
0
        public void LevelCurve()
        {
            double TempEXPNumber = 0;

            for (int i = 1; i < maxLevel; i++)
            {
                TempEXPNumber = Math.Pow(i, 2);
                Curve.Add(TempEXPNumber);
            }
            maxEXP = (int)Curve[98];
        }
Exemple #17
0
        public void When_NextSignedDouble_Expect_Reference()
        {
            // arrange
            var pdfCurve = new Curve();

            pdfCurve.Add(new Point(-1.0, 1));
            pdfCurve.Add(new Point(0, 1));
            var pdf = new Pdf(pdfCurve);

            IRandomNumberProvider baseRandom = Substitute.For <IRandomNumberProvider>();

            baseRandom.NextDouble().Returns(0.5);
            var customRandom = new CustomRandomNumberProvider(new Cdf(pdf, 10), baseRandom);

            // act
            var randomNumber = customRandom.NextSignedDouble();

            // assert
            Assert.Equal(-0.5, randomNumber);
        }
Exemple #18
0
        /// <summary>
        /// 计算电路参数,并模拟电压、电流波形
        /// </summary>
        private void Simulate()
        {
            double P   = math_P;
            double Vin = math_Vin;
            double Vo  = math_Vo;
            double fs  = math_fs;
            double L   = math_L;

            //计算电路参数
            double Ts    = 1 / fs;           //开关周期
            double Iin   = P / Vin;          //输入电流平均值
            double Io    = P / Vo;           //输出电流平均值
            double IL    = Iin;              //电感电流平均值
            double D     = 1 - (Vin / Vo);   //占空比
            double ILrip = D * Ts * Vin / L; //电感电流纹波
            double ILmax = IL + ILrip * 0.5; //电感电流峰值
            double ILmin = IL - ILrip * 0.5; //电感电流谷值

            Curve iL = new Curve();

            if (Function.GE(ILmin, 0))
            {
                //CCM
                iL.Add(0, ILmin);
                iL.Add(D * Ts, ILmax);
                iL.Add(Ts, ILmin);
            }
            else
            {
                //DCM
                ILmin = 0;
                D     = Math.Sqrt(2 * Iin * L * (Vo - Vin) / (Ts * Vin * Vo));
                double D1 = D * Vin / (Vo - Vin);
                ILmax = D * Ts * Vin / L;
                iL.Add(0, ILmin);
                iL.Add(D * Ts, ILmax);
                iL.Add((D + D1) * Ts, ILmin);
                iL.Add(Ts, ILmin);
                ILrip = ILmax;
            }

            //记录电路参数
            math_IL    = IL;
            math_ILrip = ILrip;
            curve_iS   = iL.Filter(0, D * Ts);
            curve_iD   = iL.Filter(D * Ts, Ts);
            Curve iC = curve_iD.Copy(1, 0, -Io); //电容电流波形

            math_ICrms = iC.CalcRMS();
            //Console.WriteLine(Function.EQ(iC.Integrate(), 0));
            //Graph graph = new Graph();
            //graph.Add(iC, "iC");
            //graph.Draw();
        }
 public BezierCurveDemo()
     : base("Bezier Curve")
 {
     // Generates a curve like a flower
     Curve = new Curve();
     for (var i = 0; i <= NUMBER_PETALS; i++)
     {
         var a1 = i / (float)NUMBER_PETALS * Calc.TwoPi;
         var a2 = (i + 1) / (float)NUMBER_PETALS * Calc.TwoPi;
         var p1 = Vector.FromAngle(a1);
         var p2 = Vector.FromAngle(a2);
         Curve.Add(p1 * 170F, p1 * 80, p2 * 80);
     }
 }
Exemple #20
0
 private void drawAreaPictureBox_MouseMove(object sender, MouseEventArgs e)
 {
     if (currentCurve != null && e.Button == MouseButtons.Left)
     {
         var v = new Vector()
         {
             Lat = e.Y, Lon = e.X
         };
         if ((v - currentCurve[currentCurve.Count - 1]).LengthSq >= 1000)
         {
             currentCurve.Add(v);
             curveBox.Invalidate();
         }
     }
 }
Exemple #21
0
        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
        {
            if (value is string)
            {
                var      curve   = new Curve();
                string[] entries = ((string)value).Split(new[] { ListSeparator }, StringSplitOptions.None);
                foreach (var entryText in entries)
                {
                    if (string.IsNullOrEmpty(entryText))
                    {
                        continue;
                    }

                    var p = entryText.Split(new[] { EntrySeparator });

                    if ((p.Length == 2) || (p.Length == 3 && p[0] == "lin"))                     // Backward compatibility
                    {
                        var position = new Vector2(Convert.ToSingle(p[p.Length - 2], culture), Convert.ToSingle(p[p.Length - 1], culture));
                        var entry    = new CurveEntry(position);
                        curve.Add(entry);
                    }
                    else if ((p.Length == 6) || (p.Length == 7 && p[0] == "bez"))                     // Backward compatibility
                    {
                        var position = new Vector2(Convert.ToSingle(p[p.Length - 6], culture), Convert.ToSingle(p[p.Length - 5], culture));
                        var left     = new Vector2(Convert.ToSingle(p[p.Length - 4], culture), Convert.ToSingle(p[p.Length - 3], culture));
                        var right    = new Vector2(Convert.ToSingle(p[p.Length - 2], culture), Convert.ToSingle(p[p.Length - 1], culture));
                        var entry    = new CurveEntry(position, left, right);
                        curve.Add(entry);
                    }
                }

                return(curve);
            }

            return(base.ConvertFrom(context, culture, value));
        }
        /// <summary>
        /// Reads <see cref="Control"/> statement and modifies the context.
        /// </summary>
        /// <param name="statement">A statement to process.</param>
        /// <param name="context">A context to modify.</param>
        public override void Read(Control statement, ICircuitContext context)
        {
            var curve = new Curve();

            var distributionName = statement.Parameters.First().Image;

            foreach (var param in statement.Parameters.Skip(1))
            {
                if (param is Models.Netlist.Spice.Objects.Parameters.PointParameter pp)
                {
                    var x = pp.Values.Items[0];
                    var y = pp.Values.Items[1];

                    curve.Add(new Point(context.Evaluator.EvaluateDouble(x.Image), context.Evaluator.EvaluateDouble(y.Image)));
                }
            }

            context.Evaluator.GetEvaluationContext().Randomizer.RegisterPdf(distributionName, () => new Pdf(curve));
        }
Exemple #23
0
        public override void OnDelayedWorldLoadFinished()
        {
            Overwatch.Log("FixLushEpidemic");

            if (GameUtils.IsInstalled(ProductVersion.EP9) && !GameUtils.IsUniversityWorld())
            {
                MotiveTuning mTuning = null;
                foreach (MotiveTuning tuning in MotiveTuning.GetAllTunings(CommodityKind.Juiced))
                {
                    MotiveSatisfactionCurve autoSatisfyCurve = new MotiveSatisfactionCurve
                    {
                        Loops = true
                    };
                    Curve curve = autoSatisfyCurve;
                    curve.Add(new Vector2(0f, -49f));
                    Curve motiveDecayCurve = autoSatisfyCurve.GetMotiveDecayCurve();
                    tuning.mMotiveDecayCurve = motiveDecayCurve;
                    tuning.mAutoSatisfyCurve = autoSatisfyCurve;
                    mTuning = tuning;
                }

                if (mTuning != null)
                {
                    foreach (Sim sim in LotManager.Actors)
                    {
                        if (sim == null || sim.Autonomy == null)
                        {
                            continue;
                        }

                        if (sim.Autonomy.Motives.HasMotive(CommodityKind.Juiced))
                        {
                            sim.mMotiveTuning[(int)CommodityKind.Juiced] = mTuning;
                            sim.Autonomy.Motives.RemoveMotive(CommodityKind.Juiced);
                            sim.Autonomy.Motives.CreateMotive(CommodityKind.Juiced);
                        }
                    }
                }

                Overwatch.Log("Banished autosatisfy of Juiced motive");
            }
        }
Exemple #24
0
        private static void AddAdjustmentCurvePoints(int adjustmentLevel, int[] templateTable, Curve tempCurve, ref Curve curve)
        {
            if (adjustmentLevel == 0)
            {
                return;
            }

            adjustmentLevel = ConvertAdjustmentLevel(adjustmentLevel);

            var points = new Point[templateTable.Length / 2];

            for (int i = 0; i < points.Length; ++i)
            {
                points[i] = new Point(templateTable[i * 2 + 0], templateTable[i * 2 + 1] * adjustmentLevel);
            }

            tempCurve.Points = points;

            Curve.Add(curve, tempCurve, curve);
        }
Exemple #25
0
        public void When_ComputeAreaUnderCurve_Complex_Expect_Reference()
        {
            // arrange
            var curve = new Curve();

            // act
            curve.Add(new Point(-1, 0));
            curve.Add(new Point(0, 1.0));
            curve.Add(new Point(1, 0));
            curve.Add(new Point(2, 0));
            curve.Add(new Point(2, 2));
            curve.Add(new Point(5, 2));

            // assert
            Assert.Equal(7.0, curve.ComputeAreaUnderCurve());
        }
Exemple #26
0
        private void AddRailwayToMap(CompleteWay way, List <Vector3> nodes)
        {
            // create curve with the first two nodes
            var curve = Curve.Add(map,
                                  nodes[0], nodes[1],
                                  "osm_rail");

            curve.ViewDistance  = ViewDistance;
            curve.UseLinearPath = true;

            if (way.Tags.ContainsKey("service") && (way.Tags["service"] == "siding" ||
                                                    way.Tags["service"] == "yard"))
            {
                curve.Look = "siding";
            }

            // and append the rest
            for (int i = 2; i < nodes.Count; i++)
            {
                curve = curve.Append(nodes[i], true);
            }
        }
Exemple #27
0
        public void When_ComputeAreaUnderCurveWithParameter_Expect_Reference()
        {
            // arrange
            var curve = new Curve();

            // act
            curve.Add(new Point(-1, 0));
            curve.Add(new Point(0, 1.0));
            curve.Add(new Point(1, 0));
            curve.Add(new Point(2, 0));
            curve.Add(new Point(2, 2));
            curve.Add(new Point(5, 2));

            // assert
            Assert.Equal(0, curve.ComputeAreaUnderCurve(-1.0));
            Assert.Equal(0.125, curve.ComputeAreaUnderCurve(-0.5));
            Assert.Equal(0.5, curve.ComputeAreaUnderCurve(0.0));
            Assert.Equal(0.875, curve.ComputeAreaUnderCurve(0.5));
            Assert.Equal(1.0, curve.ComputeAreaUnderCurve(1.0));
        }
Exemple #28
0
        /// <summary>
        /// 计算电路参数,并模拟电压、电流波形
        /// </summary>
        private void Simulate()
        {
            double P   = math_P;
            double Vin = math_Vin;
            double Vo  = math_Vo;
            double fs  = math_fs;
            double L   = math_L;

            //计算电路参数
            double Ts  = 1 / fs;         //开关周期
            double Iin = P / Vin;        //输入电流平均值
            double Io  = P / Vo;         //输出电流平均值
            double IL  = Iin;            //电感电流平均值
            double D   = 1 - (Vin / Vo); //占空比
            double ILrip;                //电感电流纹波

            if (D > 0.5)
            {
                ILrip = (D - 0.5) * Ts * Vin / L;
            }
            else
            {
                ILrip = D * Ts * (Vin - 0.5 * Vo) / L;
            }
            double ILmax = IL + ILrip * 0.5; //电感电流峰值
            double ILmin = IL - ILrip * 0.5; //电感电流谷值

            Curve iL = new Curve();

            if (Function.GE(ILmin, 0))
            {
                //CCM
                if (D > 0.5)
                {
                    double t1 = (D - 0.5) * Ts;
                    double t2 = 0.5 * Ts;
                    double t3 = D * Ts;
                    iL.Add(0, ILmin);
                    iL.Add(t1, ILmax);
                    iL.Add(t2, ILmin);
                    iL.Add(t3, ILmax);
                    iL.Add(Ts, ILmin);
                }
                else
                {
                    double t1 = D * Ts;
                    double t2 = 0.5 * Ts;
                    double t3 = (D + 0.5) * Ts;
                    iL.Add(0, ILmin);
                    iL.Add(t1, ILmax);
                    iL.Add(t2, ILmin);
                    iL.Add(t3, ILmax);
                    iL.Add(Ts, ILmin);
                }
            }
            else
            {
                //DCM
                ILmin = 0;
                if (D > 0.5)
                {
                    D = Math.Sqrt(2 * Iin * L * (0.5 * Vo - Vin) / (Ts * Vin * Vo)) + 0.5;
                    double D1 = Vin * (D - 0.5) / (0.5 * Vo - Vin);
                    ILmax = (D - 0.5) * Ts * Vin / L;
                    double t1 = (D - 0.5) * Ts;
                    double t2 = (D + D1 - 0.5) * Ts;
                    double t3 = 0.5 * Ts;
                    double t4 = D * Ts;
                    double t5 = (D + D1) * Ts;
                    iL.Add(0, ILmin);
                    iL.Add(t1, ILmax);
                    iL.Add(t2, ILmin);
                    iL.Add(t3, ILmin);
                    iL.Add(t4, ILmax);
                    iL.Add(t5, ILmin);
                    iL.Add(Ts, ILmin);
                }
                else
                {
                    D = Math.Sqrt(2 * Iin * L * (Vo - Vin) / (Ts * Vo * (Vin - 0.5 * Vo)));
                    double D1 = D * (Vin - 0.5 * Vo) / (Vo - Vin);
                    ILmax = D * Ts * (Vin - 0.5 * Vo) / L;
                    double t1 = D * Ts;
                    double t2 = (D + D1) * Ts;
                    double t3 = 0.5 * Ts;
                    double t4 = (D + 0.5) * Ts;
                    double t5 = (D + D1 + 0.5) * Ts;
                    iL.Add(0, ILmin);
                    iL.Add(t1, ILmax);
                    iL.Add(t2, ILmin);
                    iL.Add(t3, ILmin);
                    iL.Add(t4, ILmax);
                    iL.Add(t5, ILmin);
                    iL.Add(Ts, ILmin);
                }
                ILrip = ILmax;
            }

            //记录电路参数
            math_IL    = IL;
            math_ILrip = ILrip;
            curve_iS   = iL.Filter(0, D * Ts);
            curve_iD   = iL.Filter(D * Ts, Ts);
            Curve iC = curve_iD.Copy(1, 0, -Io); //电容电流波形

            math_ICrms = iC.CalcRMS();
        }
Exemple #29
0
 public void IsEmpty()
 {
     var curve = new Curve<int, int>();
     Assert.IsTrue(curve.IsEmpty);
     curve.Add(3, 2);
     Assert.IsFalse(curve.IsEmpty);
     curve.Clear();
     Assert.IsTrue(curve.IsEmpty);
 }
Exemple #30
0
        /// <summary>
        /// 计算电路参数,并模拟电压、电流波形
        /// </summary>
        private void Simulate()
        {
            double P   = math_P;
            double Vin = math_Vin;
            double Vo  = math_Vo;
            double fs  = math_fs;
            double L   = math_L;

            //计算电路参数
            double Ts    = 1 / fs;           //开关周期
            double Iin   = P / Vin;          //输入电流平均值
            double Io    = P / Vo;           //输出电流平均值
            double IL    = Iin * 0.5;        //电感电流平均值
            double D     = 1 - (Vin / Vo);   //占空比
            double ILrip = D * Ts * Vin / L; //电感电流纹波
            double ILmax = IL + ILrip * 0.5; //电感电流峰值
            double ILmin = IL - ILrip * 0.5; //电感电流谷值

            Curve iL = new Curve();
            Curve iC = new Curve(); //TODO 优化这里的电容电流模拟

            if (Function.GE(ILmin, 0))
            {
                //CCM
                iL.Add(0, ILmin);
                iL.Add(D * Ts, ILmax);
                iL.Add(Ts, ILmin);

                if (D > 0.5)
                {
                    iC.Add(0, -Io);
                    iC.Add((D - 0.5) * Ts, -Io);
                    iC.Add((D - 0.5) * Ts, ILmax - Io);
                    iC.Add(0.5 * Ts, ILmin - Io);
                    iC.Add(0.5 * Ts, -Io);
                }
                else
                {
                    double i1 = ILmax - ILrip / (Ts - D * Ts) * (0.5 * Ts - D * Ts);
                    double i2 = ILmax - ILrip / (Ts - D * Ts) * (0.5 * Ts);
                    iC.Add(0, i1 - Io);
                    iC.Add(D * Ts, i2 - Io);
                    iC.Add(D * Ts, ILmax + i2 - Io);
                    iC.Add(0.5 * Ts, ILmin + i1 - Io);
                    iC.Add(0.5 * Ts, i1 - Io);
                }
            }
            else
            {
                //DCM
                ILmin = 0;
                D     = Math.Sqrt(2 * IL * L * (Vo - Vin) / (Ts * Vin * Vo));
                double D1 = D * Vin / (Vo - Vin);
                ILmax = D * Ts * Vin / L;
                iL.Add(0, ILmin);
                iL.Add(D * Ts, ILmax);
                iL.Add((D + D1) * Ts, ILmin);
                iL.Add(Ts, ILmin);
                ILrip = ILmax;

                if (D > 0.5)
                {
                    iC.Add(0, -Io);
                    iC.Add((D - 0.5) * Ts, -Io);
                    iC.Add((D - 0.5) * Ts, ILmax - Io);
                    iC.Add((D + D1 - 0.5) * Ts, -Io);
                    iC.Add(0.5 * Ts, -Io);
                }
                else
                {
                    if (D1 > 0.5)
                    {
                        double i1 = ILmax - ILrip / (D1 * Ts) * (0.5 * Ts - D * Ts);
                        double i2 = ILmax - ILrip / (D1 * Ts) * (0.5 * Ts);
                        iC.Add(0, i1 - Io);
                        iC.Add(D * Ts, i2 - Io);
                        iC.Add(D * Ts, ILmax + i2 - Io);
                        iC.Add(0.5 * Ts, ILmin + i1 - Io);
                        iC.Add(0.5 * Ts, i1 - Io);
                    }
                    else if (D1 > 0.5 - D)
                    {
                        double i1 = ILmax - ILrip / (D1 * Ts) * (0.5 * Ts - D * Ts);
                        iC.Add(0, i1 - Io);
                        iC.Add((D + D1 - 0.5) * Ts, -Io);
                        iC.Add(D * Ts, -Io);
                        iC.Add(D * Ts, ILmax - Io);
                        iC.Add(0.5 * Ts, ILmin + i1 - Io);
                        iC.Add(0.5 * Ts, i1 - Io);
                    }
                    else
                    {
                        iC.Add(0, -Io);
                        iC.Add(D * Ts, -Io);
                        iC.Add(D * Ts, ILmax - Io);
                        iC.Add((D + D1) * Ts, -Io);
                        iC.Add(0.5 * Ts, -Io);
                    }
                }
            }

            //记录电路参数
            math_IL    = IL;
            math_ILrip = ILrip;
            curve_iS   = iL.Filter(0, D * Ts);
            curve_iD   = iL.Filter(D * Ts, Ts);
            math_ICrms = iC.CalcRMS();
            //Console.WriteLine(Function.EQ(iC.Integrate(), 0));
            //Graph graph = new Graph();
            //graph.Add(iC, "iC");
            //graph.Draw();
        }
        public static Curve CreateCurveFromHueRangeAdjustments(params HueRangeAdjustment[] adjustments)
        {
            Curve curve = new Curve(CurveInterpolation.Linear);

            curve.SetPoint(255, 0);
            foreach (var adjustment in adjustments)
            {
                var adjustmentLevel = ConvertAdjustmentLevel(adjustment.Adjustment);

                switch (adjustment.HueRange)
                {
                case 0:
                    curve = Curve.Add(curve, new Curve(CurveInterpolation.Linear)
                    {
                        Points = new[]
                        {
                            new Point(0, adjustmentLevel),
                            new Point(255, adjustmentLevel),
                        }
                    }, null);
                    break;

                case 1:
                    curve = Curve.Add(curve, new Curve(CurveInterpolation.Linear)
                    {
                        Points = new[]
                        {
                            new Point(0, adjustmentLevel),
                            new Point(AngleToHue(15), adjustmentLevel),
                            new Point(AngleToHue(45), 0),
                            new Point(AngleToHue(315), 0),
                            new Point(AngleToHue(345), adjustmentLevel),
                            new Point(255, adjustmentLevel),
                        }
                    }, null);
                    break;

                case 2:
                    curve = Curve.Add(curve, new Curve(CurveInterpolation.Linear)
                    {
                        Points = new[]
                        {
                            new Point(AngleToHue(15), 0),
                            new Point(AngleToHue(45), adjustmentLevel),
                            new Point(AngleToHue(75), adjustmentLevel),
                            new Point(AngleToHue(105), 0),
                            new Point(255, 0),
                        }
                    }, null);
                    break;

                case 3:
                    curve = Curve.Add(curve, new Curve(CurveInterpolation.Linear)
                    {
                        Points = new[]
                        {
                            new Point(AngleToHue(75), 0),
                            new Point(AngleToHue(105), adjustmentLevel),
                            new Point(AngleToHue(135), adjustmentLevel),
                            new Point(AngleToHue(165), 0),
                            new Point(255, 0),
                        }
                    }, null);
                    break;

                case 4:
                    curve = Curve.Add(curve, new Curve(CurveInterpolation.Linear)
                    {
                        Points = new[]
                        {
                            new Point(AngleToHue(135), 0),
                            new Point(AngleToHue(165), adjustmentLevel),
                            new Point(AngleToHue(195), adjustmentLevel),
                            new Point(AngleToHue(225), 0),
                            new Point(255, 0),
                        }
                    }, null);
                    break;

                case 5:
                    curve = Curve.Add(curve, new Curve(CurveInterpolation.Linear)
                    {
                        Points = new[]
                        {
                            new Point(AngleToHue(195), 0),
                            new Point(AngleToHue(225), adjustmentLevel),
                            new Point(AngleToHue(255), adjustmentLevel),
                            new Point(AngleToHue(285), 0),
                            new Point(255, 0),
                        }
                    }, null);
                    break;

                case 6:
                    curve = Curve.Add(curve, new Curve(CurveInterpolation.Linear)
                    {
                        Points = new[]
                        {
                            new Point(AngleToHue(255), 0),
                            new Point(AngleToHue(285), adjustmentLevel),
                            new Point(AngleToHue(315), adjustmentLevel),
                            new Point(AngleToHue(345), 0),
                            new Point(255, 0),
                        }
                    }, null);
                    break;
                }
            }

            return(curve);
        }