-
绘制抛物线(带比例缩放)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
namespace WindowsApplication1
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
{
public partial class Form1 : Form
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
private double a, b, c, d;
private Graphics paper;
private Pen pen = new Pen(Color.Black);
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
public Form1()
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
InitializeComponent();
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
private void trackBarA_Scroll(object sender, EventArgs e)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
DrawGraph();
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
private void trackBarB_Scroll(object sender, EventArgs e)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
DrawGraph();
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
private void trackBarC_Scroll(object sender, EventArgs e)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
DrawGraph();
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
private void trackBarD_Scroll(object sender, EventArgs e)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
DrawGraph();
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
private void DrawGraph()
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
paper = pictureBox1.CreateGraphics();
a = trackBarA.Value;
labelA.Text = "a=" + Convert.ToString(a);
b = trackBarB.Value;
labelB.Text = "b=" + Convert.ToString(b);
c = trackBarC.Value;
labelC.Text = "c=" + Convert.ToString(c);
d = trackBarD.Value;
labelD.Text = "d=" + Convert.ToString(d);
paper.Clear(Color.White);
Draw();
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
private void Draw()
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
double x, y, nextX, nextY;
int xPixel, yPixel, nextXPixel, nextYPixel;
for (xPixel = 0; xPixel <= pictureBox1.Width; xPixel++)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
x = ScaleX(xPixel);
y = TheFunction(x);
yPixel = ScaleY(y);
nextXPixel = xPixel + 1;
nextX = ScaleX(nextXPixel);
nextY = TheFunction(nextX);
nextYPixel = ScaleY(nextY);
paper.DrawLine(pen, xPixel, yPixel, nextXPixel, nextYPixel);
}
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
private double TheFunction(double x)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
return a * x * x * x + b * x * x + c * x + d;
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
private double ScaleX(int xPixel)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
double xStart = -5, xEnd = 5;
double xScale = pictureBox1.Width / (xEnd - xStart);
return (xPixel - (pictureBox1.Width / 2)) / xScale;
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
private int ScaleY(double y)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
double yStart = -5, yEnd = 5;
int pixelCoord;
double yScale = pictureBox1.Height / (yEnd - yStart);
pixelCoord = (int)(-y * yScale) + (int)(pictureBox1.Height / 2);
return pixelCoord;
}
}
}
-
相关阅读:
058:表关系之一对一
057:表关系之一对多
056:ORM外键删除操作详解
055:ORM外键使用详解
054:Meta类中常见配置
053:Field的常用参数详解:
052:ORM常用Field详解(3)
051:ORM常用Field详解(2)
C#中在WebClient中使用post发送数据实现方法
C# WebClient类上传和下载文件
-
原文地址:https://www.cnblogs.com/qixin622/p/715673.html
Copyright © 2020-2023
润新知