Построение графика графика квадратичной функции - C#
Формулировка задачи:
Как построить график квадратичной функции?
Построил только простую параболу, как ее сдвигать?
int ixPrev = -1, iyPrev = (int)halfH;
for (int ix = 0; ix < W; ix++)
{
float px = (ix - halfW) / halfW;
px *= (float)Math.PI;
float py = (float)Math.Pow(px, 2);
int iy = (int)(halfH - py * halfH);
g.DrawLine(Pens.Red, ixPrev, iyPrev, ix, iy);
ixPrev = ix;
iyPrev = iy;
}Решение задачи: «Построение графика графика квадратичной функции»
textual
Листинг программы
namespace draw
{
partial class Form1
{
/// <summary>
/// Требуется переменная конструктора.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Освободить все используемые ресурсы.
/// </summary>
/// <param name="disposing">истинно, если управляемый ресурс должен быть удален; иначе ложно.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Код, автоматически созданный конструктором форм Windows
/// <summary>
/// Обязательный метод для поддержки конструктора - не изменяйте
/// содержимое данного метода при помощи редактора кода.
/// </summary>
private void InitializeComponent()
{
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.num_B = new System.Windows.Forms.NumericUpDown();
this.num_C = new System.Windows.Forms.NumericUpDown();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.button1 = new System.Windows.Forms.Button();
this.txt_A = new System.Windows.Forms.TextBox();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.num_B)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.num_C)).BeginInit();
this.SuspendLayout();
//
// pictureBox1
//
this.pictureBox1.Dock = System.Windows.Forms.DockStyle.Top;
this.pictureBox1.Location = new System.Drawing.Point(0, 0);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(392, 392);
this.pictureBox1.TabIndex = 0;
this.pictureBox1.TabStop = false;
//
// num_B
//
this.num_B.Location = new System.Drawing.Point(156, 398);
this.num_B.Name = "num_B";
this.num_B.Size = new System.Drawing.Size(52, 20);
this.num_B.TabIndex = 2;
this.num_B.Value = new decimal(new int[] {
1,
0,
0,
0});
this.num_B.ValueChanged += new System.EventHandler(this.txt_A_VisibleChanged);
//
// num_C
//
this.num_C.Location = new System.Drawing.Point(292, 398);
this.num_C.Name = "num_C";
this.num_C.Size = new System.Drawing.Size(52, 20);
this.num_C.TabIndex = 3;
this.num_C.Value = new decimal(new int[] {
1,
0,
0,
0});
this.num_C.ValueChanged += new System.EventHandler(this.txt_A_VisibleChanged);
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(12, 400);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(17, 13);
this.label1.TabIndex = 4;
this.label1.Text = "A:";
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(133, 400);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(17, 13);
this.label2.TabIndex = 5;
this.label2.Text = "B:";
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(269, 400);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(17, 13);
this.label3.TabIndex = 6;
this.label3.Text = "C:";
//
// button1
//
this.button1.Location = new System.Drawing.Point(348, 396);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(43, 24);
this.button1.TabIndex = 7;
this.button1.Text = "Draw";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// txt_A
//
this.txt_A.Location = new System.Drawing.Point(35, 399);
this.txt_A.Name = "txt_A";
this.txt_A.Size = new System.Drawing.Size(61, 20);
this.txt_A.TabIndex = 8;
this.txt_A.Text = "0,5";
this.txt_A.VisibleChanged += new System.EventHandler(this.txt_A_VisibleChanged);
this.txt_A.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txt_A_KeyDown);
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(392, 426);
this.Controls.Add(this.txt_A);
this.Controls.Add(this.button1);
this.Controls.Add(this.label3);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Controls.Add(this.num_C);
this.Controls.Add(this.num_B);
this.Controls.Add(this.pictureBox1);
this.MaximumSize = new System.Drawing.Size(400, 460);
this.MinimumSize = new System.Drawing.Size(400, 460);
this.Name = "Form1";
this.Text = "Form1";
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.num_B)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.num_C)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.PictureBox pictureBox1;
private System.Windows.Forms.NumericUpDown num_B;
private System.Windows.Forms.NumericUpDown num_C;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.TextBox txt_A;
}
}