DoEvents
Next L
Loop
If VIEWXYZ = True Then
LX1 = X1 * Sin(45 * 6.28 / 360) * Cos(225 * 6.28 / 360) + Y1
LX2 = X2 * Sin(45 * 6.28 / 360) * Cos(225 * 6.28 / 360) + Y2
LY1 = X1 * Sin(45 * 6.28 / 360) * Sin(225 * 6.28 / 360) + CurrentNZ
LY2 = X2 * Sin(45 * 6.28 / 360) * Sin(225 * 6.28 / 360) + NEWZ
frmmain.Line1.X1 = LX2 * SCALESIZE
frmmain.Line1.X2 = frmmain.Line1.X1
frmmain.Line1.Y1 = LY2 * SCALESIZE
frmmain.Line1.Y2 = frmmain.Line1.Y1 + 300
If CurrentNZ = NEWZ Then
frmmain.PicDraw.Line (LX1 * SCALESIZE, LY1 * SCALESIZE)-(LX2 * SCALESIZE, LY2 * SCALESIZE), vbWhite
Else
frmmain.PicDraw.Line (LX1 * SCALESIZE, LY1 * SCALESIZE)-(LX2 * SCALESIZE, LY2 * SCALESIZE), vbWhite
End If
CurrentNZ = NEWZ
Else
frmmain.Shape1.Left = X2 * SCALESIZE - 35
frmmain.Shape1.Top = Y2 * SCALESIZE + 50
frmmain.PicDraw.Line (X1 * SCALESIZE, Y1 * SCALESIZE)-(X2 * SCALESIZE, Y2 * SCALESIZE)
End If
For L = CurrentNF * 20 To 20000 '速度控制
DoEvents
Next L
End Sub
2.2 圆弧插补模块
2.2.1 圆弧插补计算方法
以加工第一象限逆时针圆弧为例,如图2.4所示,
若点P(Xi,Yi)正好落在圆弧上,则有
Xi2+Yi2=X02+Y02=R2
若点P(Xi,Yi)在圆弧外侧,则有
Xi2+Yi2>X02+Y02=R2
若点P(Xi,Yi)在圆弧内侧,则有
Xi2+Yi2<X02+Y02=R2
上面各式可分别写成:
(Xi2—X02)+(Yi2—Y02)=0在圆弧上
(Xi2—X02)+(Yi2—Y02)>0在圆弧外侧
(Xi2—X02)+(Yi2—Y02)<0在圆弧内侧
逐点比较法圆弧插补的偏差判别式定义为:
F= Xi2+ Yi2—R2
设点P(Xi,Yi)在圆弧外侧或圆弧上,( F≥0 )可计算出新加工点偏差为
Fi+1=Fi—2Xi+1
设点P(Xi,Yi)在圆弧内侧,( F<0 )可计算出新加工点偏差为
Fi+1=Fi+2Yi+1
2.2.2 终点判断的方法
设置减法计数器,在圆弧绘制的过程中,动点与终点的距离接近时,当其距离小于脉冲当量时,给定一个误差允许的范围,当值小于这个范围,判断所绘图像到达终点。
2.2.3 其他象限圆弧插补计算
四个象限中其它象限都与第一象限或关于坐标轴对称或是关于原心对称,所以可以按第一象限逆时针圆弧插补的圆偏差公式进行计算,计算的方法完全一致,但进给方向要根据象限和顺逆进行改变。
2.1.4 直线插补流程图(如下图)
2.1.5 直线插源代码
Public Sub DrawCircle(X As Single, Y As Single, I As Single, J As Single, CircleTime As Boolean) '无插补画圆
Dim SPXY As Single, EPXY As Single, PointX(3) As Single, PointY(3) As Single, L As Single
Dim CallFOR As Single
On Error GoTo errhand
If StopRun = True Then
Exit Sub
End If
If (X - I) ^ 2 + (Y - J) ^ 2 <> CurrentNR ^ 2 And UserRTODC = False Then
Dim ErrorR As Integer
ErrorR = MsgBox("请检查你画圆的终点是否在圆周上!是否只以终点的X坐标作为标准?", vbYesNo, "错误")
If ErrorR = vbNo Then
StopRun = True 数控系统动画仿真软件设计+仿真程序(4):http://www.751com.cn/jixie/lunwen_20570.html