Ошибка при компиляция исключения

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace GraphicPlotter
{
    public partial class Form1 : Form
    {
        public Pen AxisPen = new Pen(Color.Blue, 1);
        public Pen AxisPenSecond = new Pen(Color.FromArgb(100, 0, 0, 255), 1);
        public Pen Graph = new Pen(Color.Red, 2);
        public Font AxisFont = new Font("Arial", 12);
        public Font SignatureFont = new Font("Arial", 7);
        public Font NumberFont = new Font("Arial", 8);
        public Brush FontBrush = new SolidBrush(Color.Blue);
        public Brush BlackFontBrush = new SolidBrush(Color.Black);
        public StringFormat StringFormat = new StringFormat() { FormatFlags = StringFormatFlags.DirectionRightToLeft };
        public int ScaleAxis = 7;
        public float AvgX
        {
            get
            {
                return (float)(MinX.Value + MaxX.Value) / 2;
            }
        }
        public float AvgY
        {
            get
            {
                return (float)(MinY.Value + MaxY.Value) / 2;
            }
        }
        public Form1()
        {
            InitializeComponent();
            this.Paint += PaintGraph;
            EventHandler refresh = (obj, args) => { this.Refresh(); };
            this.Resize += refresh;
            MinX.ValueChanged += refresh;
            MinY.ValueChanged += refresh;
            MaxX.ValueChanged += refresh;
            MaxY.ValueChanged += refresh;
        }
        public float Lerp(float a, float b, float c)
        {
            return a + (b - a) * c;
        }
        public float Lerp(float a, float b, float c, float offset)
        {
            return a + (b - a) * c;
        }
        public void PaintGraph(object obj, PaintEventArgs e)
        {
            Graphics graphics = e.Graphics;
            graphics.Clear(Color.White);
            int width = ActiveForm.Width;
            int height = ActiveForm.Height;
            width -= 20;
            height -= 20;
            Point center = new Point(width / 2, height / 2);
            MaxX.Value = (MaxX.Value <= MinX.Value) ? MinX.Value + 1:MaxX.Value;
            MaxY.Value = (MaxY.Value <= MinY.Value) ? MinY.Value + 1 : MaxY.Value;
            DrawAxis(graphics, center);

            List<PointF> points = new List<PointF>();
            float step = (float)(MaxX.Value - MinX.Value) / 1000;
            for (float i = (float)MinX.Value; i <= (float)MaxX.Value; i += step) //i = x
            {
                PointF pointF = new PointF(i, (float)(Math.Exp(i) * Math.Pow(i, 3)));
                points.Add(ConvertToLocal(center, pointF));
            }
            PointF[] pointsArr = points.ToArray();
            graphics.DrawLines(Graph, pointsArr);
        }
        public void DrawAxis(Graphics graphics, PointF center)
        {
            graphics.DrawLine(AxisPen, 10, center.Y, center.X * 2 - 10, center.Y);
            graphics.DrawLine(AxisPen, center.X, 10, center.X, center.Y * 2 - 10);

            graphics.DrawString("X", AxisFont, FontBrush, 2 * center.X - 5, center.Y + 10, StringFormat);
            graphics.DrawString("Y", AxisFont, FontBrush, center.X + 30, 5, StringFormat);

            graphics.DrawLine(AxisPen, center.X, 10, center.X + 5, 20);
            graphics.DrawLine(AxisPen, center.X, 10, center.X - 5, 20);

            graphics.DrawLine(AxisPen, center.X * 2 - 20, center.Y + 5, center.X * 2 - 10, center.Y);
            graphics.DrawLine(AxisPen, center.X * 2 - 20, center.Y - 5, center.X * 2 - 10, center.Y);
            //==>>
            float countX = 1.0f / center.X * 500;
            float countY = 1.0f / center.Y * 500;
            float stepX = countX * (float)(MaxX.Value - MinX.Value) / 10;
            float stepY = countY * (float)(MaxY.Value - MinY.Value) / 10;
            float avgX = AvgX;
            for (float i = avgX - stepX; i <= (float)MaxX.Value; i += stepX)
            {
                PointF pointF = ConvertToLocal(center, new PointF(i, AvgY));
                DrawVerticalLine(graphics, center, pointF, i);
            }
            for (float i = avgX - stepX; i >= (float)MinX.Value; i-= stepX)
            {
                PointF pointF = ConvertToLocal(center, new PointF(i, AvgY));
                DrawVerticalLine(graphics, center, pointF, i);
            }
            float avgY = AvgY;
            for (float i = avgY + stepY; i <= (float)MaxY.Value; i += stepY)
            {
                PointF pointF = ConvertToLocal(center, new PointF(AvgX, i));
                DrawHorizontalLine(graphics, center, pointF, i);
            }
            for (float i = avgY - stepY; i >= (float)MinY.Value; i -= stepY)
            {
                PointF pointF = ConvertToLocal(center, new PointF(AvgX, i));
                DrawHorizontalLine(graphics, center, pointF, i);
            }
        }
        public void DrawHorizontalLine(Graphics graphics, PointF center, PointF pointF, float value)
        {
            graphics.DrawLine(AxisPen, pointF.X + 3, center.Y, pointF.X - 3, center.Y);
            graphics.DrawString(value.ToString("F2"), NumberFont, BlackFontBrush, pointF);
            graphics.DrawLine(AxisPenSecond, 10, pointF.Y, center.X * 2 - 10, pointF.Y);
        }
        public void DrawVerticalLine(Graphics graphics, PointF center, PointF pointF, float value)
        {
            graphics.DrawLine(AxisPen, pointF.X, center.Y + 3, pointF.X, center.Y - 3);
            graphics.DrawString(value.ToString("F2"), NumberFont, BlackFontBrush, pointF);
            graphics.DrawLine(AxisPenSecond, pointF.X, 10, pointF.X, center.Y * 2 - 10);
        }
        public PointF ConvertToLocal(PointF center, PointF val)
        {
            float lx = (float)(MaxX.Value - MinX.Value);
            float ly = (float)(MaxY.Value - MinY.Value);

            float posX = Lerp(30, center.X * 2 - 30, (val.X - (float)MinX.Value) / lx);
            float posY = Lerp(30, center.Y * 2 - 30, 1 - (val.Y - (float)MinY.Value) / ly);

            return new PointF(posX, posY);
        }
        private void Form1_Load(object sender, EventArgs e)
        {
        }
    }
}

Нужно нарисовать функцию e^x*x^3

for (float i = (float)MinX.Value; i <= (float)MaxX.Value; i += step) //i = x
        {
            PointF pointF = new PointF(i, (float)(Math.Exp(i) * Math.Pow(i, 3)));
            points.Add(ConvertToLocal(center, pointF));
        }

при компиляции выдает исключение:System.OverflowException: "Ошибка переполнения." в этой строке graphics.DrawLines(Graph, pointsArr);


Ответы (0 шт):