C#

Copy Code

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 { lista.Add(new LinhaGCode("G01", X2, Y2, config.Z_G01)); } return lista; }