Ejemplo n.º 1
0
        public void drawRienmann(NodeHolder function, int deltaX, double fromX, double toX)
        {
            //clearing previous function and setting up variables------------------------
            lastDrawnFunction = function;
            this.fromX        = fromX;
            this.toX          = toX;
            this.deltaX       = deltaX;
            bool newSerieHasBeenUsed = false;

            for (int i = 0; i < myChart.Series.Count; i++)
            {
                if (myChart.Series[i].Color == RienmannColor)
                {
                    myChart.Series[i].Points.Clear();
                }
            }
            rienmannHasBeenDrawn = false;
            int serieCounter = nextSerie(RienmannColor, -1);

            //drawing the new function-------------------------------------------
            double answerTemp;
            double totalDistance = (toX - fromX);
            double deltaDistance = totalDistance / deltaX; //niet nauwkeurig!!
            //double halfDeltaDistance = deltaDistance / 2;
            double XStartPosition;

            for (int i = 0; i < deltaX; i++)
            {
                //try
                //{
                XStartPosition = fromX + i * deltaDistance;
                answerTemp     = function.GetFunctionOutputForX(fromX + (totalDistance + totalDistance * i * 2) / (deltaX * 2));

                if (answerTemp > myChart.ChartAreas[0].AxisY.Maximum)
                {
                    answerTemp = myChart.ChartAreas[0].AxisY.Maximum + Math.Abs(myChart.ChartAreas[0].AxisY.Maximum) * 0.1;
                }
                if (answerTemp < myChart.ChartAreas[0].AxisY.Minimum)
                {
                    answerTemp = myChart.ChartAreas[0].AxisY.Minimum - Math.Abs(myChart.ChartAreas[0].AxisY.Minimum) * 0.1;
                }

                myChart.Series[serieCounter].Points.AddXY(XStartPosition, 0);
                myChart.Series[serieCounter].Points.AddXY(XStartPosition, answerTemp);
                myChart.Series[serieCounter].Points.AddXY(XStartPosition + deltaDistance, answerTemp);
                myChart.Series[serieCounter].Points.AddXY(XStartPosition + deltaDistance, 0);
                myChart.Series[serieCounter].Points.AddXY(XStartPosition, 0);
                //}
                //catch
                //{
                //    if (newSerieHasBeenUsed)
                //    {
                //        serieCounter = nextSerie(functionColor, serieCounter);
                //        newSerieHasBeenUsed = false;
                //    }
                //}
            }
            rienmannHasBeenDrawn = true;
        }
Ejemplo n.º 2
0
 private void btnCalculateForX_Click(object sender, EventArgs e)
 {
     if (lastSelectedFunction != null)
     {
         try
         {
             double xValue = Convert.ToDouble(tbXValue.Text);
             double answer = lastSelectedFunction.GetFunctionOutputForX(xValue);
             lblCalculateForXAnswer.Text = answer.ToString();
         }
         catch
         {
             lblCalculateForXAnswer.Text = "Not Possible!";
         }
     }
 }
Ejemplo n.º 3
0
        public void drawNewton(NodeHolder function)
        {
            //clearing previous function and setting up variables------------------------
            lastDrawnFunction = function;
            bool   newSerieHasBeenUsed       = false;
            bool   yBetweenMaxAndMin         = false;
            bool   previousAnswerWasPossible = false;
            double xDistance = myChart.ChartAreas[0].AxisX.Maximum / 1000;

            if (true) //FAST RENDER = false OR ACCURATE RENDER = true
            {
                xDistance = 0.01f;
            }
            for (int i = 0; i < myChart.Series.Count; i++)
            {
                if (myChart.Series[i].Color == newtonColor && myChart.Series[i].ChartType == SeriesChartType.Line)
                {
                    myChart.Series[i].Points.Clear();
                }
            }
            newtonHasBeenDrawn = false;
            int serieCounter = nextSerie(newtonColor, -1);

            //drawing the new function-------------------------------------------
            for (double i = myChart.ChartAreas[0].AxisX.Minimum; i <= myChart.ChartAreas[0].AxisX.Maximum; i += xDistance)
            {
                try
                {
                    double answer = 0;
                    answer = (function.GetFunctionOutputForX(i + 0.01f) - function.GetFunctionOutputForX(i)) / 0.01f;
                    if (answer >= myChart.ChartAreas[0].AxisY.Minimum && answer <= myChart.ChartAreas[0].AxisY.Maximum)
                    {
                        myChart.Series[serieCounter].Points.AddXY(i, answer); //DRAW CURRENT
                        if (previousAnswerWasPossible && !yBetweenMaxAndMin)  //current point is between min/max, but previous was not, DRAW PREVIOUS
                        {
                            answer = (function.GetFunctionOutputForX(i - xDistance + 0.01f) - function.GetFunctionOutputForX(i - xDistance)) / 0.01f;
                            myChart.Series[serieCounter].Points.AddXY(i - xDistance, answer);
                        }
                        newSerieHasBeenUsed = true;
                        yBetweenMaxAndMin   = true;
                    }
                    else if (yBetweenMaxAndMin) //previous answer was between max/min, DRAW ONE MORE AND START NEW SERIE
                    {
                        myChart.Series[serieCounter].Points.AddXY(i, answer);
                        serieCounter        = nextSerie(newtonColor, serieCounter);
                        newSerieHasBeenUsed = false;
                        yBetweenMaxAndMin   = false;
                    }
                    else
                    {
                        if (newSerieHasBeenUsed)
                        {
                            serieCounter        = nextSerie(newtonColor, serieCounter);
                            newSerieHasBeenUsed = false;
                            yBetweenMaxAndMin   = false;
                        }
                    }
                    previousAnswerWasPossible = true;
                }
                catch
                {
                    if (newSerieHasBeenUsed)
                    {
                        serieCounter        = nextSerie(newtonColor, serieCounter);
                        newSerieHasBeenUsed = false;
                    }
                    previousAnswerWasPossible = false;
                }
            }
            newtonHasBeenDrawn = true;
            myChart.Invalidate();
        }