Click here to Skip to main content
15,891,938 members
Articles / Multimedia / GDI+

Midpoint Algorithm (Divide and Conquer Method) for Drawing a Simple Bezier Curve

Rate me:
Please Sign up or sign in to vote.
4.78/5 (19 votes)
8 Jul 2011CPOL3 min read 57.4K   3.1K   34  
A simple program that helps to understand the midpoint algorithm for constructing a Bezier curve.
namespace Bezier
{
    partial class CustomCanvas
    {
        /// <summary> 
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary> 
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Component Designer generated code

        /// <summary> 
        /// Required method for Designer support - do not modify 
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.panelControl = new System.Windows.Forms.Panel();
            this.btnHide = new System.Windows.Forms.Button();
            this.btnSet = new System.Windows.Forms.Button();
            this.cmbPoints = new System.Windows.Forms.ComboBox();
            this.txtIt = new System.Windows.Forms.NumericUpDown();
            this.txtY = new System.Windows.Forms.NumericUpDown();
            this.txtX = new System.Windows.Forms.NumericUpDown();
            this.lblPoints = new System.Windows.Forms.Label();
            this.label1 = new System.Windows.Forms.Label();
            this.lblIt = new System.Windows.Forms.Label();
            this.lblY = new System.Windows.Forms.Label();
            this.lblPoint = new System.Windows.Forms.Label();
            this.lblX = new System.Windows.Forms.Label();
            this.panelControl.SuspendLayout();
            ((System.ComponentModel.ISupportInitialize)(this.txtIt)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.txtY)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.txtX)).BeginInit();
            this.SuspendLayout();
            // 
            // panelControl
            // 
            this.panelControl.BackColor = System.Drawing.Color.Transparent;
            this.panelControl.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
            this.panelControl.Controls.Add(this.btnHide);
            this.panelControl.Controls.Add(this.btnSet);
            this.panelControl.Controls.Add(this.cmbPoints);
            this.panelControl.Controls.Add(this.txtIt);
            this.panelControl.Controls.Add(this.txtY);
            this.panelControl.Controls.Add(this.txtX);
            this.panelControl.Controls.Add(this.lblPoints);
            this.panelControl.Controls.Add(this.label1);
            this.panelControl.Controls.Add(this.lblIt);
            this.panelControl.Controls.Add(this.lblY);
            this.panelControl.Controls.Add(this.lblPoint);
            this.panelControl.Controls.Add(this.lblX);
            this.panelControl.Location = new System.Drawing.Point(206, 167);
            this.panelControl.Name = "panelControl";
            this.panelControl.Size = new System.Drawing.Size(134, 167);
            this.panelControl.TabIndex = 0;
            // 
            // btnHide
            // 
            this.btnHide.Location = new System.Drawing.Point(7, 133);
            this.btnHide.Name = "btnHide";
            this.btnHide.Size = new System.Drawing.Size(57, 23);
            this.btnHide.TabIndex = 4;
            this.btnHide.Text = "Hide";
            this.btnHide.UseVisualStyleBackColor = true;
            this.btnHide.Click += new System.EventHandler(this.btnHide_Click);
            // 
            // btnSet
            // 
            this.btnSet.Location = new System.Drawing.Point(70, 133);
            this.btnSet.Name = "btnSet";
            this.btnSet.Size = new System.Drawing.Size(57, 23);
            this.btnSet.TabIndex = 3;
            this.btnSet.Text = "Apply";
            this.btnSet.UseVisualStyleBackColor = true;
            this.btnSet.Click += new System.EventHandler(this.btnSet_Click);
            // 
            // cmbPoints
            // 
            this.cmbPoints.FormattingEnabled = true;
            this.cmbPoints.Items.AddRange(new object[] {
            "Point1",
            "Point2",
            "Point3"});
            this.cmbPoints.Location = new System.Drawing.Point(73, 6);
            this.cmbPoints.Name = "cmbPoints";
            this.cmbPoints.Size = new System.Drawing.Size(53, 21);
            this.cmbPoints.TabIndex = 2;
            this.cmbPoints.SelectedIndexChanged += new System.EventHandler(this.cmbPoints_SelectedIndexChanged);
            // 
            // txtIt
            // 
            this.txtIt.Location = new System.Drawing.Point(73, 81);
            this.txtIt.Maximum = new decimal(new int[] {
            20,
            0,
            0,
            0});
            this.txtIt.Name = "txtIt";
            this.txtIt.Size = new System.Drawing.Size(53, 20);
            this.txtIt.TabIndex = 1;
            // 
            // txtY
            // 
            this.txtY.DecimalPlaces = 2;
            this.txtY.Location = new System.Drawing.Point(73, 57);
            this.txtY.Maximum = new decimal(new int[] {
            10000,
            0,
            0,
            0});
            this.txtY.Name = "txtY";
            this.txtY.Size = new System.Drawing.Size(53, 20);
            this.txtY.TabIndex = 1;
            // 
            // txtX
            // 
            this.txtX.DecimalPlaces = 2;
            this.txtX.Location = new System.Drawing.Point(73, 33);
            this.txtX.Maximum = new decimal(new int[] {
            10000,
            0,
            0,
            0});
            this.txtX.Name = "txtX";
            this.txtX.Size = new System.Drawing.Size(53, 20);
            this.txtX.TabIndex = 1;
            // 
            // lblPoints
            // 
            this.lblPoints.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.lblPoints.Location = new System.Drawing.Point(63, 104);
            this.lblPoints.Name = "lblPoints";
            this.lblPoints.Size = new System.Drawing.Size(63, 17);
            this.lblPoints.TabIndex = 0;
            this.lblPoints.Text = "NONE";
            this.lblPoints.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // label1
            // 
            this.label1.AutoSize = true;
            this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.label1.Location = new System.Drawing.Point(7, 108);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(50, 13);
            this.label1.TabIndex = 0;
            this.label1.Text = "Points :";
            // 
            // lblIt
            // 
            this.lblIt.AutoSize = true;
            this.lblIt.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.lblIt.Location = new System.Drawing.Point(7, 83);
            this.lblIt.Name = "lblIt";
            this.lblIt.Size = new System.Drawing.Size(60, 13);
            this.lblIt.TabIndex = 0;
            this.lblIt.Text = "Iterations";
            // 
            // lblY
            // 
            this.lblY.AutoSize = true;
            this.lblY.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.lblY.Location = new System.Drawing.Point(7, 59);
            this.lblY.Name = "lblY";
            this.lblY.Size = new System.Drawing.Size(15, 13);
            this.lblY.TabIndex = 0;
            this.lblY.Text = "Y";
            // 
            // lblPoint
            // 
            this.lblPoint.AutoSize = true;
            this.lblPoint.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.lblPoint.Location = new System.Drawing.Point(7, 9);
            this.lblPoint.Name = "lblPoint";
            this.lblPoint.Size = new System.Drawing.Size(36, 13);
            this.lblPoint.TabIndex = 0;
            this.lblPoint.Text = "Point";
            // 
            // lblX
            // 
            this.lblX.AutoSize = true;
            this.lblX.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.lblX.Location = new System.Drawing.Point(7, 35);
            this.lblX.Name = "lblX";
            this.lblX.Size = new System.Drawing.Size(15, 13);
            this.lblX.TabIndex = 0;
            this.lblX.Text = "X";
            // 
            // CustomCanvas
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.BackColor = System.Drawing.Color.White;
            this.Controls.Add(this.panelControl);
            this.DoubleBuffered = true;
            this.Name = "CustomCanvas";
            this.Size = new System.Drawing.Size(587, 505);
            this.Load += new System.EventHandler(this.CustomCanvas_Load);
            this.Paint += new System.Windows.Forms.PaintEventHandler(this.BezierCanvas_Paint);
            this.MouseMove += new System.Windows.Forms.MouseEventHandler(this.CustomCanvas_MouseMove);
            this.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(this.CustomCanvas_MouseDoubleClick);
            this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.CustomCanvas_MouseDown);
            this.MouseUp += new System.Windows.Forms.MouseEventHandler(this.CustomCanvas_MouseUp);
            this.panelControl.ResumeLayout(false);
            this.panelControl.PerformLayout();
            ((System.ComponentModel.ISupportInitialize)(this.txtIt)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.txtY)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.txtX)).EndInit();
            this.ResumeLayout(false);

        }

        #endregion

        private System.Windows.Forms.Panel panelControl;
        private System.Windows.Forms.NumericUpDown txtIt;
        private System.Windows.Forms.NumericUpDown txtY;
        private System.Windows.Forms.NumericUpDown txtX;
        private System.Windows.Forms.Label lblIt;
        private System.Windows.Forms.Label lblY;
        private System.Windows.Forms.Label lblX;
        private System.Windows.Forms.Button btnSet;
        private System.Windows.Forms.ComboBox cmbPoints;
        private System.Windows.Forms.Label lblPoint;
        private System.Windows.Forms.Button btnHide;
        private System.Windows.Forms.Label lblPoints;
        private System.Windows.Forms.Label label1;

    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Comments and Discussions