Exemplo n.º 1
0
        private void Generate()
        {
            code = new GCodeCollector();
            double dist = 0;


            if (isClockwise)
            {
                if (stopDeg < startDeg)
                {
                    dist = startDeg - stopDeg;
                }
                else
                {
                    dist = 360 - (stopDeg - startDeg);
                }
            }
            else
            {
                if (stopDeg < startDeg)
                {
                    dist = 360 - startDeg + stopDeg;
                }
                else
                {
                    dist = stopDeg - startDeg;
                }
            }
            if (dist == 0)
            {
                dist = 360;
            }

            var startRad = MathExtension.DegreeToRadian(startDeg);
            var stopRad  = MathExtension.DegreeToRadian(stopDeg);



            double sign = isClockwise ? -1 : 1;

            Point p = new Point(center.X + AxisA / 2d * Math.Cos(startRad), center.Y + AxisB / 2d * Math.Sin(startRad));

            Code.addCode(new GCodeLine(x: p.X, y: p.Y, speed: Speed, extrude: null));
            double a       = AxisA / 2;
            double b       = AxisB / 2;
            double c       = Math.PI * (3 * (a + b) - Math.Sqrt((3 * a + b) * (a + 3 * b)));
            double degStep = Math.Min(360d / 8d, dist / (c * dist / 360 / MinArc));

            for (double i = degStep; i < dist; i += degStep)
            {
                p = new Point(center.X + AxisA / 2d * Math.Cos(MathExtension.DegreeToRadian(startDeg + i * sign)), center.Y + AxisB / 2d * Math.Sin(MathExtension.DegreeToRadian(startDeg + i * sign)));
                Code.addCode(new GCodeLine(x: p.X, y: p.Y, speed: Speed, extrude: needExtrude ? GCodeSpecial.ExtrudeLine(p, Code.LastPoint) : (double?)null));
            }

            p = new Point(center.X + AxisA / 2d * Math.Cos(stopRad), center.Y + AxisB / 2d * Math.Sin(stopRad));
            Code.addCode(new GCodeLine(x: p.X, y: p.Y, speed: Speed, extrude: needExtrude ? GCodeSpecial.ExtrudeLine(p, Code.LastPoint) : (double?)null));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Add a curve to the input GCodeCollector;
        /// </summary>
        /// <param name="code">input GCodeCollector</param>
        /// <param name="centerX">center X of curve</param>
        /// <param name="centerY">center y of curve</param>
        /// <param name="radius">radius of curve</param>
        /// <param name="startDegree">start degree of curve</param>
        /// <param name="stopDegree">start degree of curve</param>
        /// <param name="speed">The feed-rate per minute of the move between the starting point and ending point</param>
        /// <param name="needExtrude">set true for extruding</param>
        public static void Arc(GCodeCollector code, double centerX, double centerY, double radius, double startDegree, double stopDegree, double?speed = null, bool needExtrude = false, bool isClockwise = true)
        {
            double dist = 0;

            if (isClockwise)
            {
                if (stopDegree < startDegree)
                {
                    dist = startDegree - stopDegree;
                }
                else
                {
                    dist = 360 - stopDegree + startDegree;
                }
            }
            else
            {
                if (stopDegree < startDegree)
                {
                    dist = 360 - startDegree + stopDegree;
                }
                else
                {
                    dist = stopDegree - startDegree;
                }
            }


            //double dist = Math.Abs(stopDegree - startDegree);

            double sign = isClockwise ? -1 : 1;



            var p = Point.PolarToCartesian(radius, startDegree, centerX, centerY);

            code.addCode(new GCodeLine(x: p.X, y: p.Y, speed: speed, extrude: needExtrude ? GCodeSpecial.ExtrudeLine(p, code.LastPoint) : (double?)null));

            for (int i = 1; i < dist; i += 5)
            {
                p = Point.PolarToCartesian(radius, startDegree + sign * i, centerX, centerY);
                code.addCode(new GCodeLine(x: p.X, y: p.Y, speed: speed, extrude: needExtrude ? GCodeSpecial.ExtrudeLine(p, code.LastPoint) : (double?)null));
            }
            p = Point.PolarToCartesian(radius, stopDegree, centerX, centerY);
            code.addCode(new GCodeLine(x: p.X, y: p.Y, speed: speed, extrude: needExtrude ? GCodeSpecial.ExtrudeLine(p, code.LastPoint) : (double?)null));
        }