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


    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)(-* yScale) + (int)(pictureBox1.Height / 2);
                
    return pixelCoord;
            }

        }

    }
  • 相关阅读:
    dom4j解析带命名空间的xml文件
    Spring使用facotry-method创建单例Bean总结<转>
    代码审查工具StyleCop
    ReSharper 配置及用法(二)
    ReSharper 配置及用法(一)
    linqPad快速学习LINQ(含视频)
    评估期已过。有关如何升级的测试版软件的信息
    SQL批量更新数据库中所有用户数据表中字段类型为tinyint为int
    SQL SERVER获取数据库中所有表名 XTYPE类型
    sqlserver中创建链接服务器
  • 原文地址:https://www.cnblogs.com/qixin622/p/715673.html
Copyright © 2020-2023  润新知