资源预览内容
第1页 / 共11页
第2页 / 共11页
第3页 / 共11页
第4页 / 共11页
第5页 / 共11页
第6页 / 共11页
第7页 / 共11页
第8页 / 共11页
第9页 / 共11页
第10页 / 共11页
亲,该文档总共11页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述
一、 课设任务用DDA法插补第二象限直线。用逐点比较法插补第三到第二象限顺圆弧。二、课设要求 1、具有数据输入界面,有起点、终点、半径及插补步长等; 2、具有单步插补过程的动态显示功能; 3、插补的步长可调;三、编程语言Visual Basic四、功能说明本程序用逐点比较法插补第二象限的直线,及第三二象限的顺圆弧,可进行连续插补或单步插补。1、直线插补:用逐点比较法实现第二象限任意直线的插补,需要输入起点、终点坐标及步长。2、圆弧插补:用逐点比较法实现第三二象限的顺圆弧段的插补,需要输入起点、终点坐标、半径和步长。3、插补步长可调。4、可以单步执行所有插补动作,单击一次按钮执行一次插补。五、程序内容 DDA法插补第二象限直线1、源程序: Dim A, B, C, D, E, F, G, I, J, E, F As Single*连续直线插补*Private Sub Command1_Click()If (-C + A) (D - B) Then F = -C + A Else: F = D - BG = 1Do While (2 G) = E Then I = I - E * (2 G): x2 = x2 - EJ = J + (D - B)y1 = y2If (J / (2 G) = E Then J = J - E * (2 G): y2 = y2 - EPicture1.Line (x2 * Text6.Text, y2 * Text6.Text)-(x1 * Text6.Text, y1 * Text6.Text), vbGreenNext HPicture1.Line (C * Text6.Text, -D * Text6.Text)-(A * Text6.Text, -B * Text6.Text), vbRedEnd Sub*单步直线插补*Private Sub Command2_Click()If (-C + A) (D - B) Then F = -C + A Else: F = D - BG = 1Do While (2 G) = E And (J / (2 G) = E ThenPicture1.Line (x2 - E) * Text6.Text, (y2 - E) * Text6.Text)-(x2 * Text6.Text, y2 * Text6.Text), vbGreenI = I - E * (2 G)J = J - E * (2 G)x2 = x2 - Ey2 = y2 - EElseIf (I / (2 G) = E And (J / (2 G) E ThenPicture1.Line (x2 - E) * Text6.Text, y2 * Text6.Text)-(x2 * Text6.Text, y2 * Text6.Text), vbGreenI = I - E * (2 G)x2 = x2 - EElseIf (I / (2 G) = E ThenPicture1.Line (x2 * Text6.Text, (y2 - E) * Text6.Text)-(x2 * Text6.Text, y2 * Text6.Text), vbGreenJ = J - E * (2 G)y2 = y2 - EEnd IfEnd Sub3. DDA法插补第二象限直线的流程图:YNYNYNMm-1XeXeXeYeYeYe初始化xeXe,yeYe,累加次数mM,Xe、Ye清零M=0吗?Ye有溢出吗?Xe有溢出吗?+Y向走一步-X向走一步结束逐点比较法插补第三到第二象限顺圆弧1. 源程序:Dim X0, Y0, CXY, CD, CX1, CY1, CX2, CY2, CX11, CY11, CX22, CY22, ci, R, a1, b1, c1, d1, e1, x1, y1, x2, y2 As SingleCONST Pi=3.1415926*连续圆弧插补*Private Sub Command6_Click()d1 = 1 / 2 * (CX22 2 + CY22 2 - CX11 2 - CY11 2) / (CY22 - CY11)e1 = (CX11 - CX22) / (CY22 - CY11)a1 = 1 + e1 2b1 = 2 * d1 * e1 - 2 * CX11 - 2 * CY11 * e1c1 = CX11 2 + CY11 2 + d1 2 - 2 * d1 * CY11 - R 2X0 = (-b1 + Sqr(b1 2 - 4 * a1 * c1) / (2 * a1)Y0 = d1 + e1 * X0 *求得圆心If CX1 X0 And CX2 X0 Theno = Atn(CY1 - Y0) / (CX1 - X0) + Pi *起始角o1 = Atn(CY2 - Y0) / (CX2 - X0) + Pi *终止角Picture2.Circle (X0, Y0), R, vbRed, o1, oElsePicture2.Circle (X0, Y0), R, vbRed, 2 / Pi, 3 * Pi / 2End If *画圆 again: *开始插补过程If CY1 Y0 ThenIf (CX1 - X0) 2 + (CY1 - Y0) 2 = R 2 ThenPicture2.Line (CX1, CY1)-(CX1 - ci, CY1)CX1 = CX1 - ciElsePicture2.Line (CX1, CY1)-(CX1, CY1 + ci)CY1 = CY1 + ciEnd IfElseIf (CX1 - X0) 2 + (CY1 - Y0) 2 (CX1 - CX2 + ci) 2 + (CY1 - CY2) 2 Or (CX1 - CX2) 2 + (CY1 - CY2) 2 (CX1 - CX2 - ci) 2 + (CY1 - CY2) 2 Or (CX1 - CX2) 2 + (CY1 - CY2) 2 (CX1 - CX2) 2 + (CY1 - CY2 + ci) 2 Or (CX1 - CX2) 2 + (CY1 - CY2) 2 (CX1 - CX2) 2 + (CY1 - CY2 - ci) 2 ThenGoTo againElseEnd IfEnd Sub*单步圆弧插补*Private Sub Command7_Click()d1 = 1 / 2 * (CX22 2 + CY22 2 - CX11 2 - CY11 2) / (CY22 - CY11)e1 = (CX11 - CX22) / (CY22 - CY11)a1 = 1 + e1 2b1 = 2 * d1 * e1 - 2 * CX11 - 2 * CY11 * e1c1 = CX11 2 + CY11 2 + d1 2 - 2 * d1 * CY11 - R 2X0 = (-b1 + Sqr(b1 2 - 4 * a1 * c1) / (2 * a1)Y0 = d1 + e1 * X0 *求得圆心If CX1 X0 And CX2 X0 Theno = Atn(CY1 - Y0) / (CX1 - X0) + Pi *终止角o1 = Atn(CY2 - Y0) / (CX2 - X0) + Pi *终止角Picture2.Circle (X0, Y0), R, vbRed, o1, oElsePicture2.Circle (X0, Y0), R, vbRed, 2 / Pi, 3 * Pi / 2End If *画圆If (CX1 - CX2) 2 + (CY1 - CY2) 2 (CX1 - CX2 + ci) 2 + (CY1 - CY2) 2 Or (CX1 - CX2) 2 + (CY1 - CY2) 2 (CX1 - CX2 - ci) 2 + (CY1 - CY2) 2 Or (CX1 - CX2) 2 + (CY1 - CY2) 2 (CX1 - CX2) 2 + (CY1 - CY2 + ci) 2 Or (CX1 - CX2) 2 + (CY1 - CY2) 2 (CX1 - CX2) 2 + (CY1 - CY2 - ci)
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号