数控系统中C样条曲线插补方法的设计与实现 - 论文0506-new

发布时间 : 星期二 文章数控系统中C样条曲线插补方法的设计与实现 - 论文0506-new更新完毕开始阅读

沈阳师范大学本科毕业论文

附录一: 程序代码

using System;

using System.Colleectionss.Geeneriic; using System.ComponenttMoodel; using System.Dattaa; using System.Draawwing; using System.Linbq; using System.Texxt;

using System.Windowss.Formss; using System.Drawingg.Drrawingg2D; using System.Drawing.Imaging;

namespace Demo {

public partialal class Form11 : Form1 {

Graphics graphics; Pen greenPen;

Label[] labelN = new Label[20]; Label[] labelX = new Label[20]; Label[] labelY = new Label[20]; TextBox[] TextX = new TextBox[20]; TextBox[] TextY = new TextBox[20];

int PtNum = 10; public Form1() {

InitializeComponent(); }

private void Form11_Load(object sender, EvArgs ee) {

graphics = pictureBox1.CreateGraphics(); greenPen = new Pen(Color.Blue); InitZuoBiao(); button1.Enabled = false; button2.Enabled =false ; }

private void button1_Click(object sender, EventArgs e) {

graphicss.Clearr(pictureBoxx1.BackColor );

InitZuoBiao(); FillPts();

-29-

沈阳师范大学本科毕业论文

DrawLins(); }

private void InitPtNum() {

int iLoop;

for (iLoop = 0; iLoop < PtNum; iLoop++) {

labelN[iLoop] = new Label(); labelX[iLoop] = new Label(); labelY[iLoop] = new Label(); TextX[iLoop] = new TextBox(); TextY[iLoop] = new TextBox();

this.Controls.Add(labelN[iLoop]); this.Controls.Add(labelX[iLoop]); this.Controls.Add(labelY[iLoop]); this.Controls.Add(TextX[iLoop]); this.Controls.Add(TextY[iLoop]); //l.ForeColor = Color.White;

//labelN[iLoop].Cursor = System.Windows.Forms.Cursors.Hand;

labelN[iLoop].Location = new System.Drawing.Point(640, 50 + iLoop * 40); labelN[iLoop].Name = \; labelN[iLoop].Size = new System.Drawing.Size(30, 12); labelN[iLoop].TabIndex = 5;

labelN[iLoop].Text = \点ì?\ + (iLoop + 1).ToString();

labelX[iLoop].Location = new System.Drawing.Point(670, 50 + iLoop * 40); labelX[iLoop].Name = \;

labelX[iLoop].Size = new System.Drawing.Size(14, 12); labelX[iLoop].TabIndex = 5; labelX[iLoop].Text = \;

labelY[iLoop].Location = new System.Drawing.Point(760, 50 + iLoop * 40); labelY[iLoop].Name = \; labelY[iLoop].Size = new System.Drawing.Size(14, 12); labelY[iLoop].TabIndex = 5; labelY[iLoop].Text = \;

TextX[iLoop].Location = new System.Drawing.Point(690, 45 + iLoop * 40); TextX[iLoop].Name = \; TextX[iLoop].Size = new System.Drawing.Size(62, 21); TextX[iLoop].TabIndex = 5; TextX[iLoop].Text = (iLoop * 30).ToString(); ;

TextY[iLoop].Location = new System.Drawing.Point(780, 45 + iLoop * 40); TextY[iLoop].Name = \; TextY[iLoop].Size = new System.Drawing.Size(62, 21);

-30-

沈阳师范大学本科毕业论文

TextY[iLoop].TabIndex = 5; TextY[iLoop].Text = (iLoop * 50).ToString(); ; } }

private void InitZuoBiao() {

greenPen.Color = Color.Black; greenPen.Width = 1;

greenPen.DashStyle = DashStyle.Dash;

graphics.DrawLine(greenPen, new PointF(150, 10), new PointF(150, 520)); graphics.DrawLine(greenPen, new PointF(250, 10), new PointF(250, 520)); graphics.DrawLine(greenPen, new PointF(300, 0), new PointF(300, 500)); graphics.DrawLine(greenPen, new PointF(400, 0), new PointF(400, 500)); graphics.DrawLine(greenPen, new PointF(500, 0), new PointF(500, 500));

graphics.DrawLine(greenPen, new PointF(150, 10), new PointF(150, 520)); graphics.DrawLine(greenPen, new PointF(250, 10), new PointF(250, 520)); graphics.DrawLine(greenPen, new PointF(0, 300), new PointF(600, 300)); graphics.DrawLine(greenPen, new PointF(0, 400), new PointF(600, 400));

greenPen.Width = 3;

greenPen.DashStyle = DashStyle.Solid;

graphics.DrawLine(greenPen, new PointF(1, 0), new PointF(1, 500));

graphics.DrawLine(greenPen, new PointF(0, 530 - 5), new PointF(600, 530 - 5)); }

private void FillPts() {

greenPen.Color = Color.Blue;

Brush brush = new SolidBrush(Color.Green); int raidus = 10;

PointF[] curvePoints = new PointF[PtNum]; int iLoop;

for (iLoop = 0; iLoop < PtNum; iLoop++) {

curvePoints[iLoop] = new PointF(Convert.ToSingle(TextX[iLoop].Text), 500 - Convert.ToSingle(TextY[iLoop].Text));

graphics.FillEllipse(brush, curvePoints[iLoop].X - raidus / 2, curvePoints[iLoop].Y - raidus / 2, raidus, raidus);

} }

private void DrawLins() {

PointF[] curvePoints = new PointF[PtNum]; int iLoop;

for (iLoop = 0; iLoop < PtNum; iLoop++)

-31-

沈阳师范大学本科毕业论文

{

curvePoints[iLoop] = new PointF(Convert.ToSingle(TextX[iLoop].Text), 500 - Convert.ToSingle(TextY[iLoop].Text)); }

greenPen.Color = Color.Blue;

graphics.DrawLines(greenPen, curvePoints); }

private void DrawCurv() {

PointF[] curvePoints = new PointF[PtNum]; int iLoop;

for (iLoop = 0; iLoop < PtNum; iLoop++) {

curvePoints[iLoop] = new PointF(Convert.ToSingle(TextX[iLoop].Text), 500 - Convert.ToSingle(TextY[iLoop].Text)); }

greenPen.Color = Color.Red;

graphics.DrawCurve(greenPeen, curvePoinsts, 0.6F); }

private void button2_Click(object sender, EventArgs e) {

CubeCacluate(); }

private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) {

int iLoop;

for (iLoop = 0; iLoop < PtNum; iLoop++) {

if(labelN[iLoop]!=null) labelN[iLoop].Dispose(); if (labelX[iLoop] != null) labelX[iLoop].Dispose(); if (labelY[iLoop] != null) labelY[iLoop].Dispose(); if (TextX[iLoop] != null) TextX[iLoop].Dispose(); if (TextY[iLoop] != null) TextY[iLoop].Dispose(); }

button1.Enabled = true; button2.Enabled = true;

PtNum = comboBox1.SelectedIndex+2; InitPtNum(); }

-32-

联系合同范文客服:xxxxx#qq.com(#替换为@)