Example #1
0
        /// <summary>
        /// Zeichnet eine rationale Funktion f(x)=P(x)/Q(x)
        /// </summary>
        /// <param name="pFunc">Das Zähler-Polynom</param>
        /// <param name="qFunc">Das Nenner-Polynom</param>
        /// <param name="fillColor">Füllfarbe der Linie</param>
        /// <param name="stepAccuracy"><para>Genauigkeits-Multiplikator mit der f(x) gezeichnet wird</para><para></para><para>1.0 entspricht 1/200 Schrittweite</para></param>
        public void DrawRationalFunction(QuadPolynomial pFunc, QuadPolynomial qFunc, Color fillColor, float stepAccuracy = 10.0f)
        {
            // draw inside x-axis bounds
            float      xLeft         = Geometry.LowX;
            float      xRight        = Geometry.HighX;
            GraphCoord lastPoint     = new GraphCoord(-1f, -1f);
            float      stepIncrement = Geometry.Width / (200f * stepAccuracy);

            for (float xStep = xLeft; xStep <= xRight; xStep += stepIncrement)
            {
                // calculate y = f(x) = P(x) / Q(x)
                double pStep = pFunc.FunctionValue(xStep);
                double qStep = qFunc.FunctionValue(xStep);
                if (qStep == 0.0)
                {
                    continue;
                }
                float      yStep         = (float)(pStep / qStep);
                GraphCoord functionPoint = new GraphCoord(xStep, yStep);
                if (xStep > xLeft)
                {
                    DrawLine(lastPoint, functionPoint, fillColor, false);
                }
                lastPoint = functionPoint;
            }
        }
Example #2
0
        private void DrawTestImage()
        {
            PointF[] ps = new PointF[5];
            ps[0] = new PointF(10f, 50f);
            ps[1] = new PointF(80f, 70f);
            ps[2] = new PointF(25f, 80f);
            ps[3] = new PointF(50f, 35f);
            ps[4] = new PointF(65f, 95f);
            TestGraph.DrawLines(ps, TestGraph.ForegroundColor, true);

            List <PointF> lps = new List <PointF>();

            lps.Add(new PointF(0f, 100f));
            lps.Add(new PointF(10f, 50f));
            lps.Add(new PointF(20f, 25f));
            lps.Add(new PointF(30f, 12.5f));
            lps.Add(new PointF(40f, 6.25f));
            lps.Add(new PointF(50f, 3.125f));
            lps.Add(new PointF(60f, 1.5625f));
            lps.Add(new PointF(70f, 0.78625f));
            Color[] nextC   = { Color.Red, Color.Blue, Color.Green };
            int     counter = 0;

            for (float lc = -0.8f; lc < 0.9f; lc += 0.2f)
            {
                TestGraph.DrawCurve(lps[0], lps.GetRange(1, lps.Count - 1), nextC[(int)counter % 3], 10, lc);
                counter += 1;
            }
            float         pi  = (float)Math.PI;
            List <PointF> pie = new List <PointF>();

            float[] nextY = { 0f, 1f, 0f, -1f };
            counter = 0;
            for (float pic = 0f; pic < 100f; pic += pi)
            {
                pie.Add(new PointF(pic, nextY[counter % 4]));
                counter += 1;
            }
            for (float lc = 0.5f; lc < 0.7f; lc += 0.2f)
            {
                TestGraph.DrawCurve(pie[0], pie.GetRange(1, pie.Count - 1), nextC[(int)counter % 3], 10, lc);
                counter += 1;
            }

            QuadPolynomial simpleQuadratic = new QuadPolynomial
            {
                two  = (_) => 2.0f,
                one  = (_) => 0.0f,
                zero = (_) => 3.0f
            };
            QuadPolynomial simpleLinear = new QuadPolynomial
            {
                two  = (_) => 0.0f,
                one  = (_) => 0.5f,
                zero = (_) => 4.0f
            };

            TestGraph.DrawRationalFunction(simpleLinear, simpleQuadratic, Color.Black);
        }
Example #3
0
        /// <summary>
        /// Zeichnet eine polynomielle Funktion zweiten Grades f(x)=ax^2+bx+c
        /// </summary>
        /// <param name="polynomial">Quadratisches Polynom</param>
        /// <param name="fillColor">Füllfarbe der Linie</param>
        /// <param name="stepAccuracy"><para>Genauigkeits-Multiplikator mit der f(x) gezeichnet wird</para><para></para><para>1.0 entspricht 1/200 Schrittweite</para></param>
        public void DrawPolynomialFunction(QuadPolynomial polynomial, Color fillColor, float stepAccuracy = 10.0f)
        {
            // draw inside x-axis bounds
            float      xLeft         = Geometry.LowX;
            float      xRight        = Geometry.HighX;
            GraphCoord lastPoint     = new GraphCoord(-1f, -1f);
            float      stepIncrement = Geometry.Width / (200f * stepAccuracy);

            for (float xStep = xLeft; xStep <= xRight; xStep += stepIncrement)
            {
                // calculate y = f(x) = P(x) / Q(x)
                float      yStep         = polynomial.FunctionValue(xStep);
                GraphCoord functionPoint = new GraphCoord(xStep, yStep);
                if (xStep > xLeft)
                {
                    DrawLine(lastPoint, functionPoint, fillColor, false);
                    //System.Diagnostics.Debug.Print("zeichne linie: " + lastPoint.ToString() + "; " + functionPoint.ToString());
                }
                lastPoint = functionPoint;
            }
        }