Ejemplo n.º 1
0
        public void ParameterPlot(Func<double, PointD> Function, double start, double end, int slices, Action<PolyLine> PolyLineSetter = null)
        {

            #region 主要計算
            PolyLine polyline = new PolyLine();

            if (start > end)
            {
                double newEnd = start;
                start = end;
                end = newEnd;
            }
            double dx = (end - start) / slices;
            if (Function != null)
            {
                for (double x = start; x <= end; x += dx)
                    polyline.AddPoint(Function(x));
                if (PolyLineSetter != null)
                    PolyLineSetter(polyline);
                else
                    polyline.Color = System.Drawing.Color.LawnGreen;
            }
            #endregion

            Action BeginPlot = () =>
            {
                #region
                if (Window != null)
                    Window.View.AddSomeThing2Show(polyline);
                #endregion
            };

            //因為牽扯到視窗元素,所以需委托應用程式的STA執行緒來執行
            Application.Current.Dispatcher.BeginInvoke(BeginPlot);
        }
Ejemplo n.º 2
0
 public PolyLine GetSegmentsAsPL(int i, int slice)
 {
     Console.WriteLine();
     PointD[] p = new PointD[slice + 1];
     PointD[] cP = new PointD[] { ControlPoints[i], ControlPoints[i + 1], ControlPoints[i + 2], ControlPoints[i + 3] };
     //Nci
     double[,] Nci = GetNci(i, DataOutput);
     
     for (int j = 0; j < slice + 1; j++)
     {
         double tou = (double)j * 1.0 / (double)slice;
         Double[,] touM = new Double[,] { { 1, tou, tou * tou, tou * tou * tou } };
         double[,] cc = MatrixDot(touM, Nci);
         if (DataOutput)
         {
             //Console.WriteLine(i + "tou:" + tou);
             //foreach (var item in touM)
             //{
             //    Console.Write(item + ",");
             //}
             //Console.WriteLine("");
             //foreach (var item in cc)
             //{
             //    Console.Write(item + ",");
             //}
             //Console.WriteLine("");
             //Console.WriteLine(i + "th segments sum of Blenging sum:" + (cc[0, 0] + cc[0, 1] + cc[0, 2] + cc[0, 3]));
         }
         p[j] = (cc[0, 0] * cP[0] + cc[0, 1] * cP[1] + cc[0, 2] * cP[2] + cc[0, 3] * cP[3]);
     }
     Random rnd = new Random(Guid.NewGuid().GetHashCode());
     PolyLine aPlyLine = new PolyLine(p) { Color = System.Drawing.Color.FromArgb(255, rnd.Next(256), rnd.Next(256), rnd.Next(256)), LineWidth = 2 };
     //aPlyLine = new PolyLine(ControlPoints) { Color = this.Color };
     return aPlyLine;
 }
Ejemplo n.º 3
0
 public PolyLine[] ToPolylines(int slice)
 {
     int n = DataPoints.Length;
     PolyLine[] polylines = new PolyLine[n - 1];
     for (int i = 0; i < polylines.Length; i++)
     {
         polylines[i] = GetSegmentsAsPL(i, slice);
     }
     return polylines;
 }
Ejemplo n.º 4
0
        public PolyLine[] ToPolyline(int slice)
        {
            if (DataPoints != null && ControlPoints != null)
            {
                int n = DataPoints.Length;
                PointD[] p = new PointD[(n - 1) * slice + 1];
                for (int i = 0; i < n - 1; i++)
                {
                    PointD[] cP = new PointD[] { ControlPoints[i], ControlPoints[i + 1], ControlPoints[i + 2], ControlPoints[i + 3] };
                    //Nci
                    double[,] Nci = GetNci(i, DataOutput);

                    Console.WriteLine();
                    for (int j = 0; j < slice + 1; j++)
                    {
                        double tou = (double)j * 1.0 / (double)slice;
                        double[,] cc = MatrixDot(new Double[,] { { 1, tou, tou * tou, tou * tou * tou } }, Nci);
                        //Console.WriteLine(i + "th segments sum of Blenging sum:" + (cc[0, 0] + cc[0, 1] + cc[0, 2] + cc[0, 3]));
                        p[i * slice + j] = (cc[0, 0] * cP[0] + cc[0, 1] * cP[1] + cc[0, 2] * cP[2] + cc[0, 3] * cP[3]);
                    }
                }
                PolyLine aPlyLine = new PolyLine(p) { Color = this.Color, LineWidth = 2 };
                //aPlyLine = new PolyLine(ControlPoints) { Color = this.Color };
                return new PolyLine[] { aPlyLine };
            }
            else
                return null;
        }
Ejemplo n.º 5
0
        public void AddNewMonitor(String Name = "", Action<PolyLine> Setter = null)
        {
            Action action = () =>
            {
                PolyLine newRecord = new PolyLine();

                if (String.IsNullOrEmpty(Name))
                    Name = "Monitor " + MonitorRecords.Count;

                if (Setter != null)
                    Setter(newRecord);

                MonitorRecords.Add(Name, newRecord);
            };
            Application.Current.Dispatcher.BeginInvoke(action);
        }
Ejemplo n.º 6
0
        public void PlotLine(PolyLine polyline)
        {
            Action BeginPlot = () =>
            {
                #region
                if (Window != null)
                    Window.View.AddSomeThing2Show(polyline);
                #endregion
            };

            //因為牽扯到視窗元素,所以需委托應用程式的STA執行緒來執行
            Application.Current.Dispatcher.BeginInvoke(BeginPlot);
        }
Ejemplo n.º 7
0
        public override object Clone()
        {
            PolyLine aPolyLine = new PolyLine();
            if (this.Name != null)
                aPolyLine.Name = this.Name;
            aPolyLine.Color = this._color;
            aPolyLine.LineType = this.LineType;
            aPolyLine.LineWidth = this.LineWidth;

            int nump = this.Points.Count;
            aPolyLine.Points = new List<PointD>();
            for (int i = 0; i < nump; i++)
                aPolyLine.Points.Add(this.Points[i].Clone() as PointD);
            return aPolyLine;
        }