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;
}
}
}
查看全文
相关阅读:
AjaxControlToolKit(整理)三.......(35个控件)简单介绍
C#多线程学习
《深入浅出WPF》视频列表
【Redis】Redis功能及性能
MySQL性能优化
【Redis】Redis常用命令
php项目相关资源
JAVA基础知识总结:十一
JAVA基础知识总结:九
JAVA基础知识总结:十
原文地址:https://www.cnblogs.com/qixin622/p/715673.html
最新文章
摊还分析
Logger 源码解析 MyLogger
vbcrlf
截取字符串长度代码
通过复选框批量添加内容到textarea
javascript页面跳转常用代码
VB数据类型转换函数
VBScript 函数
ASP中使用SQL时的数据类型转换
FLASH脚本语言详解
热门文章
asp中“文字”变量的查询
chr码值对应列表大全(收藏)
jquery id选择器 id带"."问题
js 限制input输入字节长度
springmvc @responseBody自动打包json出现错误(外键查询死循环)问题
shiro 更改登录的用户名
HashTable与Dictionary<TKey, TValue>
.NET开发中你可能会用到的常用方法总结
js操作html的table,包括添加行,添加列,删除行,删除列,合并单元格
Canvas、StackPanel、Grid三者之间的关系
Copyright © 2011-2022 走看看