zoukankan
html css js c++ java
绘制抛物线(带比例缩放)
using
System;
using
System.Collections.Generic;
using
System.ComponentModel;
using
System.Data;
using
System.Drawing;
using
System.Text;
using
System.Windows.Forms;
namespace
WindowsApplication1
{
public
partial
class
Form1 : Form
{
private
double
a, b, c, d;
private
Graphics paper;
private
Pen pen
=
new
Pen(Color.Black);
public
Form1()
{
InitializeComponent();
}
private
void
trackBarA_Scroll(
object
sender, EventArgs e)
{
DrawGraph();
}
private
void
trackBarB_Scroll(
object
sender, EventArgs e)
{
DrawGraph();
}
private
void
trackBarC_Scroll(
object
sender, EventArgs e)
{
DrawGraph();
}
private
void
trackBarD_Scroll(
object
sender, EventArgs e)
{
DrawGraph();
}
private
void
DrawGraph()
{
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();
}
private
void
Draw()
{
double
x, y, nextX, nextY;
int
xPixel, yPixel, nextXPixel, nextYPixel;
for
(xPixel
=
0
; xPixel
<=
pictureBox1.Width; xPixel
++
)
{
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);
}
}
private
double
TheFunction(
double
x)
{
return
a
*
x
*
x
*
x
+
b
*
x
*
x
+
c
*
x
+
d;
}
private
double
ScaleX(
int
xPixel)
{
double
xStart
=
-
5
, xEnd
=
5
;
double
xScale
=
pictureBox1.Width
/
(xEnd
-
xStart);
return
(xPixel
-
(pictureBox1.Width
/
2
))
/
xScale;
}
private
int
ScaleY(
double
y)
{
double
yStart
=
-
5
, yEnd
=
5
;
int
pixelCoord;
double
yScale
=
pictureBox1.Height
/
(yEnd
-
yStart);
pixelCoord
=
(
int
)(
-
y
*
yScale)
+
(
int
)(pictureBox1.Height
/
2
);
return
pixelCoord;
}
}
}
查看全文
相关阅读:
wpf arcgis engine 当前没有或未启用Spatial Analyst许可解决办法
arcglobe 图层三大类说明
sql自带函数语句
wpf 前台获取资源文件路径问题
Microsoft.Office.Interop.Excel的用法
WPF:父窗口与子窗口的层次关系
wpf 拖图片到窗体
wpf comboBox取值问题
wpf 窗体内容旋转效果 网摘
js拖动滑块
原文地址:https://www.cnblogs.com/qixin622/p/715673.html
最新文章
【python】使用matplotlib绘制热力图,入门版
【python】使用pyheatmap.heatmap绘制热力图,入门版2
【python】地图热力图随机经纬度格式生成器
【python】使用python按照一定格式批量输出,地图热力图经纬度格式生成器
【python】使用pyheatmap.heatmap制作热力图,入门版
【机器学习】sklearn库的安装教程,python
【机器学习】读取txt文本内容计算TF-IDF值,算法,python
【机器学习】sklearn库的学习之TF-IDF算法,python,超简单!
【python】使用matplotlib绘制线形图,plt.show(),超简单
【机器学习】sklearn鸢尾花识别,python
热门文章
键盘KeyCode对照表
JS之数组代码
JS之自动更新的时间代码
JS之逻辑运算符代码
JS函数之判断数据类型代码
JS之匿名函数立即调用模式代码
JS中形参和实参的区别
如何正确的使用PHP手册?
PHPStorm2017设置字体与设置浏览器访问
Windows下Composer的安装和使用教程+删除教程
Copyright © 2011-2022 走看看