绘制抛物线(带比例缩放)

 

None.gif using  System;
None.gif
using  System.Collections.Generic;
None.gif
using  System.ComponentModel;
None.gif
using  System.Data;
None.gif
using  System.Drawing;
None.gif
using  System.Text;
None.gif
using  System.Windows.Forms;
None.gif
None.gif
namespace  WindowsApplication1
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    
public partial class Form1 : Form
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
private double a, b, c, d;
InBlock.gif        
private Graphics paper;
InBlock.gif        
private Pen pen = new Pen(Color.Black);
InBlock.gif
InBlock.gif        
public Form1()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            InitializeComponent();
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
private void trackBarA_Scroll(object sender, EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            DrawGraph();
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
private void trackBarB_Scroll(object sender, EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            DrawGraph();
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
private void trackBarC_Scroll(object sender, EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            DrawGraph();
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
private void trackBarD_Scroll(object sender, EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            DrawGraph();
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
private void DrawGraph()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            paper 
= pictureBox1.CreateGraphics();
InBlock.gif            a 
= trackBarA.Value;
InBlock.gif            labelA.Text 
= "a=" + Convert.ToString(a);
InBlock.gif            b 
= trackBarB.Value;
InBlock.gif            labelB.Text 
= "b=" + Convert.ToString(b);
InBlock.gif            c 
= trackBarC.Value;
InBlock.gif            labelC.Text 
= "c=" + Convert.ToString(c);
InBlock.gif            d 
= trackBarD.Value;
InBlock.gif            labelD.Text 
= "d=" + Convert.ToString(d);
InBlock.gif            paper.Clear(Color.White);
InBlock.gif            Draw();
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
private void Draw()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
double x, y, nextX, nextY;
InBlock.gif            
int xPixel, yPixel, nextXPixel, nextYPixel;
InBlock.gif            
for (xPixel = 0; xPixel <= pictureBox1.Width; xPixel++)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                x 
= ScaleX(xPixel);
InBlock.gif                y 
= TheFunction(x);
InBlock.gif                yPixel 
= ScaleY(y);
InBlock.gif                nextXPixel 
= xPixel + 1;
InBlock.gif                nextX 
= ScaleX(nextXPixel);
InBlock.gif                nextY 
= TheFunction(nextX);
InBlock.gif                nextYPixel 
= ScaleY(nextY);
InBlock.gif                paper.DrawLine(pen, xPixel, yPixel, nextXPixel, nextYPixel);           
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
private double TheFunction(double x)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
return a * x * x * x + b * x * x + c * x + d;
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
private double ScaleX(int xPixel)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
double xStart = -5, xEnd = 5;
InBlock.gif            
double xScale = pictureBox1.Width / (xEnd - xStart);
InBlock.gif            
return (xPixel - (pictureBox1.Width / 2)) / xScale;
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
private int ScaleY(double y)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
double yStart = -5, yEnd = 5;
InBlock.gif            
int pixelCoord;
InBlock.gif            
double yScale = pictureBox1.Height / (yEnd - yStart);
InBlock.gif            pixelCoord 
= (int)(-* yScale) + (int)(pictureBox1.Height / 2);
InBlock.gif            
return pixelCoord;
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值