我的任务是使用点数组绘制函数图。这是。
如何绘制坐标轴?
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 pr14
{
public partial class Form2 : Form
{
protected override void OnPaint(PaintEventArgs e)
{
// интервал
const int minX = -2;
const int maxX = 5;
PointF[] points = new PointF[maxX - minX];
for (int i = 0; i < points.Length; i++)
{
float x = i + minX;
if (x <= 3)
points[i] = new PointF(x, 2 - x);
else points[i] = new PointF(x, x * x);
}
//нормирование точек
float w = this.ClientSize.Width;
float h = this.ClientSize.Height;
float minY = points[0].Y;
float maxY = points[0].Y;
for (int i = 1; i < points.Length; i++)
{
if (minY > points[i].Y) minY = points[i].Y;
if (maxY < points[i].Y) maxY = points[i].Y;
}
for (int i = 0; i < points.Length; i++)
{
points[i].X = w * (points[i].X - minX) / (maxX - minX);
points[i].Y = h - h * (points[i].Y - minY) / (maxY - minY);
}
e.Graphics.DrawLines(Pens.Blue, points);
}
}
}
对于 OX 轴,用 Y 坐标画一条线
X 坐标为 0 的起点,终点为 c
w
对于 OY 轴,X 坐标为