15,035,283 members
See more:
I am writing an application in VB.net to convert a DXF file to GCode for my GRBL laser. I know there are many free or low cost programs out there, but I want this program to work in a very specific way (for too many reasons to explain here). I have been working on this program for about 6 months and am at my last "step".

I need some help converting the Arc segment of a Polyline to GCode (using G02 or G03).

By standard, the DXF stores the arc segment as start point, end point, and bulge. So I have these 3 variables. I know that the radius of the arc is 4*Atan(bulge), so I can figure the angle of the arc. What I need is how to convert this to GCode (or .nc file) using G02 or G03. I know that a +bulge is counterclockwise, and -bulge is clockwise, so that's no big deal.

But now what? G02 and G3 requires the center of the arc... but how do I get it? Is there another way of going about this?

I would be very, VERY grateful for any help here. Thank you!

What I have tried:

Google search, DXF-to-GCode Converter, Autodesk Fusion 360
Posted
Updated 2-May-18 19:34pm

## Solution 1

Here in C# ...

C#
```public static List<LinhaGCode> Bulge2IJ(double X1, double Y1, double X2, double Y2, double Bulge, Config config)
{
double C = 0; //lunghezza della corda - length of the cord
double H = 0; //altezza del triangolo - height of the triangle
double alpha2 = 0; //mezzo angolo di arco  - half arc angle
double beta = 0; //angolo della corda rispetto agli assi - orientation of the segment
List<LinhaGCode> lista = new List<LinhaGCode>();
double I, J, R;

if (Bulge != 0)
{
C = Math.Sqrt(Math.Pow((X2 - X1), 2) + Math.Pow((Y2 - Y1), 2));
alpha2 = Math.Atan(Bulge) * 2;
R = Math.Abs(C / (2 * Math.Sin(alpha2)));
H = Math.Sqrt(Math.Pow(R, 2) - Math.Pow((C / 2), 2));

if ((Bulge > 1) || ((Bulge < 0) && (Bulge > -1)))
{
alpha2 = alpha2 + Math.PI;
}

if (X1 != X2)
{
beta = Math.Atan(System.Convert.ToDouble(Y2 - Y1) / System.Convert.ToDouble(X2 - X1));
if (X2 < X1)
{
beta = beta + Math.PI;
}
}
else
{
if (Y2 < Y1)
{
beta = (-1) * (Math.PI / 2);
}
else
{
beta = Math.PI / 2; ;
}
}

if ((Bulge > 1) || ((Bulge < 0) && (Bulge > -1)))
{
I = (X2 - X1) / 2 + (Math.Cos(beta - Math.PI / 2) * H);
J = (Y2 - Y1) / 2 + (Math.Sin(beta - Math.PI / 2) * H);
}
else
{
I = (X2 - X1) / 2 - (Math.Cos(beta - Math.PI / 2) * H);
J = (Y2 - Y1) / 2 - (Math.Sin(beta - Math.PI / 2) * H);
}
if (Bulge > 0)
{
lista.Add(new LinhaGCode("G03", X2, Y2, config.Z_G03, I, J));
}
else
{
lista.Add(new LinhaGCode("G02", X2, Y2, config.Z_G03, I, J));
}
}
else
{
}
return lista;
}```
v2

Top Experts
Last 24hrsThis month
 OriginalGriff 100 Richard MacCutchan 68 Richard Deeming 65 k5054 25 Dave Kreskowiak 20
 OriginalGriff 2,887 Richard Deeming 1,778 Richard MacCutchan 1,590 CPallini 1,003 Dave Kreskowiak 716

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900