📄 form1.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace 工程曲线
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.MainMenu mainMenu1;
private System.Windows.Forms.MenuItem menuItem1;
private System.Windows.Forms.MenuItem menuItem2;
private System.Windows.Forms.MenuItem menuItem3;
private System.Windows.Forms.PictureBox pictureBox1;
public Point p=new Point();
public Point p1=new Point();
public Point p2=new Point();
public Point p3=new Point();
public Point p4=new Point();
public Point p5=new Point();
int num=0;
private System.Windows.Forms.MenuItem menuItem4;
private System.Windows.Forms.MenuItem menuItem5;
private System.Windows.Forms.MenuItem menuItem7;
private System.Windows.Forms.MenuItem menuItem8;
private System.Windows.Forms.MenuItem menuItem9;
private System.Windows.Forms.MenuItem menuItem10;
private System.Windows.Forms.MenuItem menuItem11;
private System.Windows.Forms.MenuItem menuItem12;
private System.Windows.Forms.MenuItem menuItem14;
private System.Windows.Forms.MenuItem menuItem15;
private System.Windows.Forms.MenuItem menuItem16;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.mainMenu1 = new System.Windows.Forms.MainMenu();
this.menuItem1 = new System.Windows.Forms.MenuItem();
this.menuItem2 = new System.Windows.Forms.MenuItem();
this.menuItem3 = new System.Windows.Forms.MenuItem();
this.menuItem4 = new System.Windows.Forms.MenuItem();
this.menuItem5 = new System.Windows.Forms.MenuItem();
this.menuItem7 = new System.Windows.Forms.MenuItem();
this.menuItem8 = new System.Windows.Forms.MenuItem();
this.menuItem9 = new System.Windows.Forms.MenuItem();
this.menuItem10 = new System.Windows.Forms.MenuItem();
this.menuItem11 = new System.Windows.Forms.MenuItem();
this.menuItem12 = new System.Windows.Forms.MenuItem();
this.menuItem14 = new System.Windows.Forms.MenuItem();
this.menuItem15 = new System.Windows.Forms.MenuItem();
this.menuItem16 = new System.Windows.Forms.MenuItem();
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// mainMenu1
//
this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem1,
this.menuItem4,
this.menuItem7,
this.menuItem14});
//
// menuItem1
//
this.menuItem1.Index = 0;
this.menuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem2,
this.menuItem3});
this.menuItem1.Text = "圆弧曲线";
//
// menuItem2
//
this.menuItem2.Index = 0;
this.menuItem2.Text = "圆弧";
this.menuItem2.Click += new System.EventHandler(this.menuItem2_Click);
//
// menuItem3
//
this.menuItem3.Index = 1;
this.menuItem3.Text = "三点画弧";
this.menuItem3.Click += new System.EventHandler(this.menuItem3_Click);
//
// menuItem4
//
this.menuItem4.Index = 1;
this.menuItem4.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem5});
this.menuItem4.Text = "三次参数样条插值曲线";
//
// menuItem5
//
this.menuItem5.Index = 0;
this.menuItem5.Text = "三次参数样条插值曲线程序";
this.menuItem5.Click += new System.EventHandler(this.menuItem5_Click);
//
// menuItem7
//
this.menuItem7.Index = 2;
this.menuItem7.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem8,
this.menuItem9,
this.menuItem10,
this.menuItem11,
this.menuItem12});
this.menuItem7.Text = "贝济埃曲线";
//
// menuItem8
//
this.menuItem8.Index = 0;
this.menuItem8.Text = "一次贝济埃曲线";
this.menuItem8.Click += new System.EventHandler(this.menuItem8_Click);
//
// menuItem9
//
this.menuItem9.Index = 1;
this.menuItem9.Text = "二次贝济埃曲线";
this.menuItem9.Click += new System.EventHandler(this.menuItem9_Click);
//
// menuItem10
//
this.menuItem10.Index = 2;
this.menuItem10.Text = "三次贝济埃曲线";
this.menuItem10.Click += new System.EventHandler(this.menuItem10_Click);
//
// menuItem11
//
this.menuItem11.Index = 3;
this.menuItem11.Text = "二次贝济埃曲线一般程序";
this.menuItem11.Click += new System.EventHandler(this.menuItem11_Click);
//
// menuItem12
//
this.menuItem12.Index = 4;
this.menuItem12.Text = "三次贝济埃曲线一般程序";
this.menuItem12.Click += new System.EventHandler(this.menuItem12_Click);
//
// menuItem14
//
this.menuItem14.Index = 3;
this.menuItem14.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem15,
this.menuItem16});
this.menuItem14.Text = "B样条曲线";
//
// menuItem15
//
this.menuItem15.Index = 0;
this.menuItem15.Text = "二次B样条曲线";
this.menuItem15.Click += new System.EventHandler(this.menuItem15_Click);
//
// menuItem16
//
this.menuItem16.Index = 1;
this.menuItem16.Text = "三次B样条曲线";
this.menuItem16.Click += new System.EventHandler(this.menuItem16_Click);
//
// pictureBox1
//
this.pictureBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.pictureBox1.BackColor = System.Drawing.SystemColors.ActiveCaptionText;
this.pictureBox1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.pictureBox1.Location = new System.Drawing.Point(8, 8);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(544, 384);
this.pictureBox1.TabIndex = 0;
this.pictureBox1.TabStop = false;
this.pictureBox1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.pictureBox1_MouseDown);
//
// label1
//
this.label1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.label1.Location = new System.Drawing.Point(240, 400);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(136, 23);
this.label1.TabIndex = 1;
//
// label2
//
this.label2.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.label2.Location = new System.Drawing.Point(408, 400);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(144, 23);
this.label2.TabIndex = 2;
//
// label3
//
this.label3.Location = new System.Drawing.Point(24, 400);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(160, 23);
this.label3.TabIndex = 3;
this.label3.Text = "可用鼠标画三次贝济埃曲线";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(560, 429);
this.Controls.Add(this.label3);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Controls.Add(this.pictureBox1);
this.Menu = this.mainMenu1;
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void menuItem2_Click(object sender, System.EventArgs e)
{
PointF p1=new Point();
PointF p2=new Point();
Graphics g=pictureBox1.CreateGraphics();
Pen pen1=new Pen(Color.Blue);
g.Clear(pictureBox1.BackColor);
double pi=3.14159;
int R=120;
double t1,t2,t;
t1=pi/4;
t2=pi;
double x,y;
int x0=220;
int y0=180;
for(t=t1;t<t2;t=t+pi/100)
{
x=x0+R*Math.Cos(t);
y=y0-R*Math.Sin(t);
if(t==t1)
{
p1.X=(float)x;
p1.Y=(float)y;
}
else
{
p2.X=(float)(x);
p2.Y=(float)(y);
g.DrawLine(pen1,p1,p2);
p1=p2;
}
}
}
private void menuItem3_Click(object sender, System.EventArgs e)
{
Graphics g=pictureBox1.CreateGraphics();
Pen pen1=new Pen(Color.Blue);
g.Clear(pictureBox1.BackColor);
int i,j;
double[] xx=new double[3]{90.0,200.0,100.0};
double[] yy=new double[3]{90.0,100.0,30.0};
double[] aa=new double[3];
double[] bb=new double[3];
double[] cc=new double[3];
double[] tt=new double[3];
double d,x,y,pai,pai2,r,a,b,a1,b1,n1;
double x1,y1,cs,ss,sx,t,p;
p1.X=(int)xx[0];
p1.Y=(int)yy[0];
for(i=0;i<=1;i++)
{
aa[i]=xx[i]-xx[2];
bb[i]=yy[i]-yy[2];
cc[i]=(aa[i]*(xx[i]+xx[2])+bb[i]*(yy[i]+yy[2]))/2;
}
d=aa[0]*bb[1]-aa[1]*bb[0];
if(Math.Abs(d)<=.000001)
{
p2.X=(int)xx[2];
p2.Y=(int)yy[2];
p3.X=(int)xx[1];
p3.Y=(int)yy[1];
g.DrawLine(pen1,p1,p2);
g.DrawLine(pen1,p2,p3);
}
x=(cc[0]*bb[1]-cc[1]*bb[0])/d;
y=(aa[0]*cc[1]-aa[1]*cc[0])/d;
p4.X=(int)xx[0];
p4.Y=(int)yy[0];
pai=3.14159;
pai2=2*pai;
r=Math.Sqrt(Math.Pow(xx[0]-x,2)+Math.Pow(yy[0]-y,2));
for(i=0;i<=2;i++)
{
a=xx[i]-x;
b=yy[i]-y;
a1=Math.Abs(a);
b1=Math.Abs(b);
if(a1>b1)
{
tt[i]=Math.Atan(b1/a1);
}
else
{
tt[i]=pai/2-Math.Atan(a1/b1);
}
if(a<0)
{
tt[i]=pai-Math.Sign(b)*tt[i];
}
if(a>=0&&b<0)
{
tt[i]=pai2-tt[i];
}
}
if(tt[1]-tt[0]<0)tt[1]=tt[1]+pai2;
if(tt[2]-tt[0]<0)tt[2]=tt[2]+pai2;
p=Math.Sign(tt[1]-tt[2]);
if(p==1)
{
t=tt[1]-tt[0];
}
else
{
t=-(tt[0]+pai2-tt[1]);
}
n1=Math.Abs((int)(t*r));
x1=xx[0];
y1=yy[0];
cs=Math.Cos(p/r);
ss=Math.Sin(p/r);
for(j=1;j<=n1;j+=1)
{
sx=x+(x1-x)*cs-(y1-y)*ss;
y1=(y+(x1-x)*ss+(y1-y)*cs);
x1=sx;
p5.X=(int)x1;
p5.Y=(int)y1;
g.DrawLine(pen1,p4.X,p4.Y+60,p5.X,p5.Y+60);
p4=p5;
}
}
private void menuItem5_Click(object sender, System.EventArgs e)
{
Graphics g=pictureBox1.CreateGraphics();
Pen pen1=new Pen(Color.Blue);
g.Clear(pictureBox1.BackColor);
double[] x=new double[100];
double[] y=new double[100];
double[] a=new double[100];
double[] b=new double[100];
double[] c=new double[100];
double[] px=new double[100];
double[] py=new double[100];
double[] qx=new double[100];
double[] qy=new double[100];
double[] tt=new double[100];
double[] dx=new double[100];
double[] dy=new double[100];
int i,n=4,t,es=3;
double bx3,bx4=0.0,by3=0.0,by4;
int cx,cy;
for(i=0;i<=n;i++)
{
a[i]=0.0;b[i]=0.0;c[i]=0.0;px[i]=0.0;py[i]=0.0;
dx[i]=0.0;dy[i]=0.0;tt[i]=0.0;qx[i]=0.0;qy[i]=0.0;
}
px[0]=1.0;py[0]=1.0;
px[4]=1.0;py[4]=1.0;
x[0]=10.0;y[0]=110.0;
x[1]=40.0;y[1]=100.0;
x[2]=80.0;y[2]=90.0;
x[3]=130.0;y[3]=95.0;
x[4]=200.0;y[4]=105.0;
p1.X=(int)x[0];
p1.Y=(int)y[0];
for(i=0;i<=n;i++)
{
p2.X=(int)x[i];
p2.Y=(int)y[i];
}
p3.X=(int)x[0];
p3.Y=(int)y[0];
for(i=1;i<=n;i++)
{
tt[i]=Math.Sqrt((x[i]-x[i-1])*(x[i]-x[i-1])+(y[i]-y[i-1])*(y[i]-y[i-1]));
}
if(n==1)
{
goto p0;
}
for(i=1;i<=n-1;i++)
{
a[i]=2*(tt[i]+tt[i+1]);
b[i]=tt[i+1];
c[i]=tt[i];
dx[i]=3*(tt[i]*(x[i+1]-x[i])/tt[i+1]+tt[i+1]*(x[i]-x[i-1])/tt[i]);
dy[i]=3*(tt[i]*(y[i+1]-y[i])/tt[i+1]+tt[i+1]*(y[i]-y[i-1])/tt[i]);
}
dx[i]=dx[1]-tt[2]*px[0];dx[n-1]=dx[n-1]-tt[n-1]*px[n];
dy[i]=dy[1]-tt[2]*py[0];dy[n-1]=dy[n-1]-tt[n-1]*py[n];
if(n==2)
{
px[1]=dx[1]/a[1];
py[1]=dy[1]/a[1];
goto p0;
}
c[1]=c[1]/a[1];
for(i=2;i<=n-1;i++)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -