예제 #1
0
        public PointPairList getIntersections(PointPairList points1, PointPairList points2)
        {
            // Возвращает список точек пересечения ломаной с линией f
            PointPairList p = new PointPairList();
            double xl = points1[0].X;
            double xend = points1[points1.Count - 1].X;
            double step = 0.01;
            while (xl < xend)
            {
                double xr = xl + step;
                if ((points1.SplineInterpolateX(xl, tension) - points2.SplineInterpolateX(xl, tension))
                    * (points1.SplineInterpolateX(xr, tension) - points2.SplineInterpolateX(xr, tension)) <= 0)
                {
                    p.Add((xl + xr) / 2.0, points1.SplineInterpolateX((xl + xr) / 2.0, tension));
                }
                xl = xr;

            }
            return p;
        }
예제 #2
0
파일: Form1.cs 프로젝트: Jungwon/ZedGraph
        private void CreateGraph_SplineTest( ZedGraphControl z1 )
        {
            GraphPane myPane = z1.GraphPane;
            PointPairList ppl = new PointPairList();

            ppl.Add( 4000, 150 );
            ppl.Add( 7360, 333 );
            ppl.Add( 10333.333, 45.333336 );
            ppl.Add( 11666.667, 5 );
            ppl.Add( 12483.333, 45.333336 );
            ppl.Add( 13600, 110 );
            ppl.Add( 15800, 184.66667 );
            //			ppl.Add( 18000, 187.5 );
            ppl.Add( 18644.998, 186.33368 );
            //ppl.Add( 18770.002, 186.66664 );
            //ppl.Add( 18896.666, 187.08336 );
            //ppl.Add( 18993.334, 187.50002 );
            ppl.Add( 19098.332, 188.08334 );
            //ppl.Add( 19285.002, 189.41634 );
            //ppl.Add( 19443.332, 190.83334 );
            ppl.Add( 19633.334, 193.16634 );
            //ppl.Add( 19823.336, 196.49983 );
            //ppl.Add( 19940.002, 199.16669 );
            //ppl.Add( 20143.303, 204.66566 );
            ppl.Add( 20350, 210.91667 );
            //			ppl.Add( 21000, 232 );
            //			ppl.Add( 23000, 296 );
            ppl.Add( 24000, 100 );

            //double y1 = ppl.SplineInterpolateX( 18000, 0.2 );
            //double y2 = ppl.SplineInterpolateX( 21000, 0.2 );
            //double y3 = ppl.SplineInterpolateX( 23000, 0.2 );
            //ppl.Add( 18000, y1 );
            //ppl.Add( 21000, y2 );
            //ppl.Add( 23000, y3 );
            //ppl.Sort();

            LineItem curve = myPane.AddCurve( "test", ppl, Color.Green, SymbolType.Default );
            curve.Line.IsSmooth = true;
            curve.Line.SmoothTension = 0.5F;

            PointPairList ppl2 = new PointPairList();
            for ( double x = 4100; x < 24000; x += 100 )
            {
                double y = ppl.SplineInterpolateX( x, 0.5 );
                ppl2.Add( x, y );
            }

            LineItem curve2 = myPane.AddCurve( "interp", ppl2, Color.Red, SymbolType.Circle );

            z1.ZoomButtons2 = MouseButtons.Left;
            z1.ZoomModifierKeys2 = Keys.Control;

            z1.MouseDownEvent += new ZedGraphControl.ZedMouseEventHandler( Spline_MouseDownEvent );
            z1.MouseUpEvent += new ZedGraphControl.ZedMouseEventHandler( Spline_MouseUpEvent );
        }
예제 #3
0
파일: Form1.cs 프로젝트: Jungwon/ZedGraph
        // Simple plot with interpolated difference curve
        private void CreateGraph_DifferencePlot( ZedGraphControl z1 )
        {
            GraphPane myPane = z1.GraphPane;

            // Generate the first data set
            PointPairList list1 = new PointPairList();
            for ( int i = 0; i < 13; i++ )
            {
                double x = i + 11.0;
                double y = 150.0 * ( 1.0 + Math.Sin( i * 0.3 ) );
                list1.Add( x, y );
            }

            // Generate a second data set that is unrelated to the first
            PointPairList list2 = new PointPairList();
            for ( int i = 0; i < 15; i++ )
            {
                double x = i * 1.2 + 10.0;
                double y = 250.0 * ( 1.0 + Math.Sin( x * 0.5 ) );

                list2.Add( x, y );
            }

            // Make sure the data are sorted and monotonically increasing
            list1.Sort();
            list2.Sort();
            // Get the lower and upper limit of the data
            // This code can throw an exception if either list is empty
            double xMin = Math.Min( list1[0].X, list2[0].X );
            double xMax = Math.Max( list1[list1.Count - 1].X, list2[list2.Count - 1].X );

            // Create a new list that will hold the difference points
            PointPairList diffList = new PointPairList();

            // Select the number of points for the new difference curve
            // This is completely arbitrary, but more points will make it smoother in the
            // case of SplineInterpolation
            const int count = 50;

            // Loop for each data point to be created in the new PointPairList
            for ( int i=0; i<count; i++ )
            {
                // Calculated X values are evenly spaced
                double x = xMin + (double) i * ( xMax - xMin ) / count;

                // Use spline interpolation to create the Y values for the new curve
                // Note that this allows extrapolation beyond the actual data available
                // A tension value of 0.5 is used, but anywhere between 0 and 1 is reasonable
                //double y = list1.InterpolateX( x );
                double y1 = list1.InterpolateX( x );
                double y2 = list2.SplineInterpolateX( x, 0.5 );

                // Add the new Point to the list taking the difference between the Y values
                // If either value is Missing, it means that a point was extrapolated beyond
                // the available data, which is not allowed for SplineInterpolateX()
                // This won't happen with InterpolateX, since it allows extrapolation
                if ( y1 == PointPair.Missing || y2 == PointPair.Missing )
                    diffList.Add( x, PointPair.Missing, PointPair.Missing );
                else
                    diffList.Add( x, y1 - y2, (y1-y2) > 0 ? 1 : 0 );
            }

            // Create the three curves -- two datasets, plus a difference curve
            LineItem diffCurve = myPane.AddCurve( "diff", diffList, Color.Red, SymbolType.None );
            LineItem myCurve1 = myPane.AddCurve( "curve", list1, Color.Blue, SymbolType.Diamond );
            LineItem myCurve2 = myPane.AddCurve( "curve 2", list2, Color.Green, SymbolType.Circle );
            Color[] colors = { Color.Red, Color.Green };
            diffCurve.Line.Fill = new Fill( colors, 90 );
            diffCurve.Line.Fill.RangeMin = 0;
            diffCurve.Line.Fill.RangeMax = 1;
            diffCurve.Line.Fill.Type = FillType.GradientByZ;

            //diffCurve.Line.GradientFill = new Fill( colors, 90 );
            //diffCurve.Line.GradientFill.RangeMin = -100;
            //diffCurve.Line.GradientFill.RangeMax = 200;

            //diffCurve.Line.IsOptimizedDraw = true;

            // Add some "pretty" stuff (optional)
            myCurve1.Symbol.Fill = new Fill( Color.White );
            myCurve2.Symbol.Fill = new Fill( Color.White );
            diffCurve.Line.Width = 2.0f;
            //diffCurve.Symbol.Fill = new Fill( Color.White );
            myPane.Title.Text = "Interpolated Data Curve";
            myPane.XAxis.Title.Text = "Period";
            myPane.YAxis.Title.Text = "Response";
            myPane.Legend.FontSpec.Size = 14;
            myPane.Fill = new Fill( Color.WhiteSmoke, Color.Lavender, 0F );
            myPane.Chart.Fill = new Fill( Color.FromArgb( 255, 255, 245 ),
               Color.FromArgb( 255, 255, 190 ), 90F );

            XDate xx = new XDate( 2007, 11, 9 );
            XDate x2 = new XDate( 2007, 11, 9 );
            XDate x3 = new XDate( 2007, 11, 9, 1, 1, 1 );

            object junk = new object();

            int i1 = xx.CompareTo( xx );
            int i2 = xx.CompareTo( x2 );
            int i3 = xx.CompareTo( x3 );
            int i4 = x2.CompareTo( xx );
            int i5 = x2.CompareTo( x3 );
            int i6 = x3.CompareTo( x2 );
            int i7 = x3.CompareTo( junk );

            z1.IsAntiAlias = true;
            z1.AxisChange();
        }