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;
}
}
}
查看全文
相关阅读:
不吐不快之EJB演练——开篇概述
URL重写:RewriteCond指令与RewriteRule 指令格式
刚到公司有点压力山大,在此希望有大神给点正能量
053第449题
选择排序---简单选择排序 堆排序
bzoj-1492 货币兑换Cash (2)——CDQ分治
MySQL 提高Insert性能
Codeforces Round #313 (Div. 2) 560C Gerald's Hexagon(脑洞)
Matlab矩阵基础
Android 带清除功能的输入框控件EditTextWithDel
原文地址:https://www.cnblogs.com/qixin622/p/715673.html
最新文章
P1903 【模板】分块/带修改莫队(数颜色)
FHQ Treap小结(神级数据结构!)
P3391 文艺平衡树
P3369 【模板】普通平衡树(Treap/SBT)
P2746 [USACO5.3]校园网Network of Schools
P2341 [HAOI2006]受欢迎的牛
Tarjan中栈的分析与SLT栈的实现
[置顶] Objective-C ,ios,iphone开发基础:ios数据库(The SQLite Database),使用终端进行简单的数据库操作
[LeetCode] Print All Combinations of a Number as a Sum of Candidate Numbers
linux进程解析--进程的创建
热门文章
android使用xfire webservice框架远程对sqlserver操作(包括增删改查)的实例!!已在真机上试验通过
JSTL解析——001
ClusterWare 服务介绍
编程时遇到概率加密或概率签名后要注意的问题
11661
map对象建立家族姓氏查询
Creating, detaching, re-attaching, and fixing a SUSPECT database
MVC总结--数据传递
Public Private Protect Inheritance and access specifiers
[物理题+枚举] hdu 4445 Crazy Tank
Copyright © 2011-2022 走看看