private static void drawSlotLine(Point pStart, Point pEnd, double xInch) { double r = scaleValue(xInch) / 2; if (logCoordinate) { Logger.Trace("drawSlotLine pStart:x:{0:0.00} y:{1:0.00} pEnd:x:{2:0.00} y:{3:0.00} r:{4:0.00} ", pStart.X, pStart.Y, pEnd.X, pEnd.Y, r); } if (pStart == pEnd) { Logger.Error("..same coordinates x:{0} y:{1}, nothing to do", pStart.X, pStart.Y); return; } double quarter = Math.PI / 2; double angle = gcodeMath.getAlpha(pStart, pEnd); Point p1l = calcOffsetPoint(pStart, angle + quarter, r); Point p1r = calcOffsetPoint(pStart, angle - quarter, r); Point p2l = calcOffsetPoint(pEnd, angle + quarter, r); Point p2r = calcOffsetPoint(pEnd, angle - quarter, r); //Logger.Trace(" drawSlotLine pStart:x:{0:0.00} y:{1:0.00} p1l:x:{2:0.00} y:{3:0.00} p1r:x:{4:0.00} y:{5:0.00} ",pStart.X,pStart.Y,p1l.X,p1l.Y,p1r.X,p1r.Y); Graphic.StopPath(); isPenDown = false; // Graphic.StartPath(p1l); penDown(p1l); Graphic.AddLine(p2l); Graphic.AddArc(true, p2r, sub(pEnd, p2l)); Graphic.AddLine(p1r); Graphic.AddArc(true, p1l, sub(pStart, p1r)); Graphic.StopPath(); isPenDown = false; StartCoordinate = pEnd; }
private static void drawSlotArc(Point pStart, bool isCW, Point pEnd, Point IJ, double xInch) { double r = scaleValue(xInch) / 2; if (logCoordinate) { Logger.Trace("drawSlotArc pStart:x:{0:0.00} y:{1:0.00} pEnd:x:{2:0.00} y:{3:0.00} r:{4:0.00} ", pStart.X, pStart.Y, pEnd.X, pEnd.Y, r); } Point center = sub(pEnd, IJ); double angle = gcodeMath.getAlpha(center, pStart); Point p1out = calcOffsetPoint(pStart, angle, r); Point p1in = calcOffsetPoint(pStart, angle - Math.PI, r); angle = gcodeMath.getAlpha(center, pEnd); Point p2out = calcOffsetPoint(pEnd, angle, r); Point p2in = calcOffsetPoint(pEnd, angle - Math.PI, r); // isCW? Graphic.StopPath(); isPenDown = false; //Graphic.StartPath(p1out); penDown(p1out); Graphic.AddArc(true, p2out, sub(pEnd, p2out)); Graphic.AddArc(true, p2in, sub(pEnd, p2out)); Graphic.AddArc(true, p1in, sub(pStart, p2in)); Graphic.AddArc(true, p1out, sub(pStart, p1in)); Graphic.StopPath(); isPenDown = false; StartCoordinate = pEnd; }
private static void AddRoundCorner(double bulge, double p1x, double p1y, double p2x, double p2y) { //Definition of bulge, from Autodesk DXF fileformat specs double angle = Math.Abs(Math.Atan(bulge) * 4); bool girou = false; //For my method, this angle should always be less than 180. if (angle > Math.PI) { angle = Math.PI * 2 - angle; girou = true; } //Distance between the two vertexes, the angle between Center-P1 and P1-P2 and the arc radius double distance = Math.Sqrt(Math.Pow(p1x - p2x, 2) + Math.Pow(p1y - p2y, 2)); double alpha = (Math.PI - angle) / 2; double ratio = distance * Math.Sin(alpha) / Math.Sin(angle); if (angle == Math.PI) { ratio = distance / 2; } double xc, yc, direction; //Used to invert the signal of the calculations below bool isg2 = bulge < 0; if (isg2) { direction = 1; } else { direction = -1; } //calculate the arc center double part = Math.Sqrt(Math.Pow(2 * ratio / distance, 2) - 1); if (!girou) { xc = ((p1x + p2x) / 2) - direction * ((p1y - p2y) / 2) * part; yc = ((p1y + p2y) / 2) + direction * ((p1x - p2x) / 2) * part; } else { xc = ((p1x + p2x) / 2) + direction * ((p1y - p2y) / 2) * part; yc = ((p1y + p2y) / 2) - direction * ((p1x - p2x) / 2) * part; } Graphic.AddArc(isg2, p2x, p2y, (xc - p1x), (yc - p1y), ""); }
private static void Draw() { Point tmp = scalePosition(setX, setY); if (logDetailed) { Logger.Trace("++++Draw() X:{0:0.000} Y:{1:0.000} isPenDown:{2} gMode:{3}", tmp.X, tmp.Y, isPenDown, gMode); } if (gMode == 1) { if ((actualAperture.apType == aperture.type.none) || (actualAperture.XSize == 0)) { if (logCoordinate) { Logger.Trace("....AddLine X:{0:0.000} Y:{1:0.000} ", tmp.X, tmp.Y); } Graphic.AddLine(tmp); isPenDown = true; } else { drawSlotLine(StartCoordinate, tmp, actualAperture.XSize); } } // move to with pen down else { if ((actualAperture.apType == aperture.type.none) || (actualAperture.XSize == 0)) { if (logCoordinate) { Logger.Trace("....AddArc X:{0:0.000} Y:{1:0.000} I:{2:0.00} J:{3:0.00} ", tmp.X, tmp.Y, setI, setJ); } Graphic.AddArc((gMode == 2), tmp, scalePosition(setI, setJ)); } else { drawSlotArc(StartCoordinate, (gMode == 2), tmp, scalePosition(setI, setJ), actualAperture.XSize); } } lastMove = tmp; }
private static void drawSlotLine(Point pStart, Point pEnd, double xInch) { double r = scaleValue(xInch) / 2; Logger.Trace("drawSlotLine pStart:x:{0:0.00} y:{1:0.00} pEnd:x:{2:0.00} y:{3:0.00} r:{4:0.00} ", pStart.X, pStart.Y, pEnd.X, pEnd.Y, r); double quarter = Math.PI / 2; double angle = gcodeMath.getAlpha(pStart, pEnd); Point p1l = calcOffsetPoint(pStart, angle + quarter, r); Point p1r = calcOffsetPoint(pStart, angle - quarter, r); Point p2l = calcOffsetPoint(pEnd, angle + quarter, r); Point p2r = calcOffsetPoint(pEnd, angle - quarter, r); Logger.Trace(" drawSlotLine pStart:x:{0:0.00} y:{1:0.00} p1l:x:{2:0.00} y:{3:0.00} p1r:x:{4:0.00} y:{5:0.00} ", pStart.X, pStart.Y, p1l.X, p1l.Y, p1r.X, p1r.Y); Graphic.StopPath(); Graphic.StartPath(p1l); Graphic.AddLine(p2l); Graphic.AddArc(true, p2r, sub(pEnd, p2l)); Graphic.AddLine(p1r); Graphic.AddArc(true, p1l, sub(pStart, p1r)); Graphic.StopPath(); StartCoordinate = pEnd; }
private static void drawSlotArc(Point pStart, bool isCW, Point pEnd, Point IJ, double xInch) { double r = scaleValue(xInch) / 2; Point center = sub(pEnd, IJ); double angle = gcodeMath.getAlpha(center, pStart); Point p1out = calcOffsetPoint(pStart, angle, r); Point p1in = calcOffsetPoint(pStart, angle - Math.PI, r); angle = gcodeMath.getAlpha(center, pEnd); Point p2out = calcOffsetPoint(pEnd, angle, r); Point p2in = calcOffsetPoint(pEnd, angle - Math.PI, r); // isCW? Graphic.StopPath(); Graphic.StartPath(p1out); Graphic.AddArc(true, p2out, sub(pEnd, p2out)); Graphic.AddArc(true, p2in, sub(pEnd, p2out)); Graphic.AddArc(true, p1in, sub(pStart, p2in)); Graphic.AddArc(true, p1out, sub(pStart, p1in)); Graphic.StopPath(); StartCoordinate = pEnd; }