如何从GCODE在C#中正确使用DrawArc?

时间:2019-04-01 11:47:17

标签: c# .net winforms g-code

我正在尝试从GCode绘制弧线(使用Graphics.DrawArc),但是当我将其与https://ncviewer.com/网站的结果进行比较时,C#的结果是不同的。 我将坐标系更改为从左按钮开始。

我正在使用以下库:
-geometry3sharp
-gsGcode

GCode:

G90 G64 G80 G17 G21 G40 G49 G50 G94
M1221
M5
G0      x25.10430     y35.10093
M4
M1
M3
G2      x33.76455     y20.10093    i0.0000000  j-10.0000000
G2      x25.10430     y35.10093   i-8.6602500    j5.0000000
M5
G0     x100.10430     y50.10093
M4
M1
M3
G1       x0.10430     y50.10093
G1       x0.10430      y0.10093
G1     x100.10430      y0.10093
G1     x100.10430     y50.10093
M5
M30

C#代码:

else if (gc.type == GCodeLine.LType.GCode && gc.code == 2)
{
    if (gc.parameters[0].identifier.ToUpper() == "X")
        xparam = gc.parameters[0].intValue;
    else
        continue;
    if (gc.parameters[1].identifier.ToUpper() == "Y")
        yparam = gc.parameters[1].intValue;
    else
        continue;
    if (gc.parameters[2].identifier.ToUpper() == "I")
        iparam = gc.parameters[2].intValue;
    else
        continue;
    if (gc.parameters[3].identifier.ToUpper() == "J")
        jparam = gc.parameters[3].intValue;
    else
        continue;

    long x = xparam;
    long y = gbitmap.Height-1 - yparam;

    // GeometryUtils.CalcArc3Points(xstartpos, ystartpos,iparam,jparam, x, y);
    // 
     g3.Arc2d arc = new g3.Arc2d(new g3.Vector2d(iparam, jparam), new g3.Vector2d(xstartpos, ystartpos),new g3.Vector2d(x, y));

     newgraphic.DrawArc(new Pen(Color.Red, 1f),(float)arc.P0.x, (float)arc.P0.y, (float)arc.P1.x, (float)arc.P1.x, (float)arc.AngleStartDeg, (float)arc.AngleEndDeg);

    xstartpos = x;
    ystartpos = y;

}

来自MyApp的GCODE图片

GCODE image from MyApp

网站上的GCODE图片

GCODE image from website

如果我从此行更改代码:

 newgraphic.DrawArc(new Pen(Color.Red, 1f),(float)arc.P0.x, (float)arc.P0.y, (float)arc.P1.x, (float)arc.P1.x, (float)arc.AngleStartDeg, (float)arc.AngleEndDeg);

收件人:

 newgraphic.DrawArc(new Pen(Color.Red, 1f),(float)arc.P0.x, (float)arc.P0.y, (float)arc.P1.x, (float)arc.P1.y, (float)arc.AngleStartDeg, (float)arc.AngleEndDeg);

我得到以下图像: Image after code change

0 个答案:

没有答案