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;
}
}
}
查看全文
相关阅读:
wingIDE Pro6 破解教程
C++中的访问权限
解决wine中文字体方块或乱码
linux下目录的作用
linux下查看系统信息
Windows Eclipse Maven 安装
Centos SVN 搭建
Mysql MyISAM 与 InnoDB 效率
Linux删除除指定后缀外的所有文件
mysql 多个timestamp设置自动更新 错误:there can be only one TIMESTAMP column with CURRENT_TIMESTAMP
原文地址:https://www.cnblogs.com/qixin622/p/715673.html
最新文章
Comparing the contribution of NBA draft picks(转)
Building [Security] Dashboards w/R & Shiny + shinydashboard(转)
RFM模型——构建数据库营销的商业战役!(转)
数据挖掘应用案例:RFM模型分析与客户细分(转)
R语言&页游渠道分析(转)
iOS开发系统版本适配(未完待续。。。)
在苹果公司申请公司开发者账号所需资料
The account '...' is no team with ID '...'
iOS开发使用MJRefresh进行刷新
IOS开发使用YiRefresh进行刷新
热门文章
iOS开发者的福利 — — iOS9+Xcode7免越狱免证书直接调试
IOS9提示“不受信任的开发者”如何处理
UIPickerView
转化秒数为正规的时间格式{NSString格式的秒数转成NSDate格式后再以NSString形式输出)
iOS9网络适配
hexo修改Next主题的样式
sublime-text3打造markdown编辑器
让sublime可以和visual studio一样自动在运算符前后添加空格的插件
LeetCode 2. Add Two Numbers
LeetCode 1. Two Sum
Copyright © 2011-2022 走看看