Задача: построить график полинома не выше пятой степени.
Т.к. с с# я только начал работу, затруднения по задаче.. Облазил много тем, понял что рисовать можно и просто на форме, и панель на форму засунуть, и ещё другие способы... Перепробовал всё, что только нашёл, не помогает... Прошу помочь разобраться... Что же всё-таки лучше пихать на форму и как рисовать...
Ах да, сторонние модули, типа ZedGraph, использовать нельзя.
Вот мои наработки:
Код:
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 graphsharp
{
public struct PointD {
public double X;
public double Y;
public PointD(double x, double y) {
X = x;
Y = y;
}
public Point ToPoint() {
return new Point((int)X, (int)Y);
}
public override bool Equals(object obj) {
return obj is PointD && this == (PointD)obj;
}
public override int GetHashCode() {
return X.GetHashCode() ^ Y.GetHashCode();
}
public static bool operator ==(PointD a, PointD b) {
return a.X == b.X && a.Y == b.Y;
}
public static bool operator !=(PointD a, PointD b) {
return !(a == b);
}
}
public partial class Form1 : Form
{
private const double diapazon_min = -100;
private const double diapazon_max = 100;
private const double inc_step = 1;
PointD[] arr;
public Form1()
{
InitializeComponent();
}
private void label5_Click(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
double[] a = new double[6];
a[0] = Convert.ToDouble(textBox1.Text);
a[1] = Convert.ToDouble(textBox2.Text);
a[2] = Convert.ToDouble(textBox3.Text);
a[3] = Convert.ToDouble(textBox4.Text);
a[4] = Convert.ToDouble(textBox5.Text);
a[5] = Convert.ToDouble(textBox6.Text);
// graphic(a);
}
/* public void graphic(double[] a)
{
double shag = 1;
// double mashtab = 30;
int fillHeight = 500;
int fillWidth = 1000;
int otstup = 5;
Graphics e = this.CreateGraphics();
SolidBrush brush = new SolidBrush(Color.Brown);
e.FillRectangle(brush, new Rectangle(otstup, otstup, fillWidth, fillHeight));
// e.FillRectangle(brush, new Rectangle(otstup, 2*otstup+fillHeight, fillWidth, fillHeight));
int n=Convert.ToInt32(fillWidth/shag);
Point[] y = new Point[n];
int p = 0;
for (double x = 0; x < fillWidth; x += shag)
{
y[p]=new Point(Convert.ToInt32(x+otstup),Convert.ToInt32(((a[0] * x * x * x * x * x + a[1] * x * x * x * x + a[2] * x * x * x + a[3] * x * x + a[4] * x + a[5])+fillHeight/2)+otstup));
p++;
}
Pen pen = new Pen(Color.Black);
e.DrawCurve(pen, y);
}*/
private void Form1_Load(object sender, EventArgs e)
{
arr = new PointD[(int)(((diapazon_max - diapazon_min) / inc_step) + 1)];
int c = 0;
for (double x = diapazon_min; x < diapazon_max; x++)
{
arr[c] = new PointD(x, Func(x));
c++;
}
}
private double Func(double x)
{
double[] a = new double[6];
a[0] = Convert.ToDouble(textBox1.Text);
a[1] = Convert.ToDouble(textBox2.Text);
a[2] = Convert.ToDouble(textBox3.Text);
a[3] = Convert.ToDouble(textBox4.Text);
a[4] = Convert.ToDouble(textBox5.Text);
a[5] = Convert.ToDouble(textBox6.Text);
return (a[0] * x * x * x * x * x + a[1] * x * x * x * x + a[2] * x * x * x + a[3] * x * x + a[4] * x + a[5]);
}
}
}