Beispiel #1
0
        public CNCPoint MiddlePointXY(CNCPoint pt)
        {
            double x = (pt.x + this.x) / 2;
            double y = (pt.y + this.y) / 2;

            return(new CNCPoint(x, y, 0));
        }
Beispiel #2
0
        public GCodeLine(string l, GCodeLine prevLn)
        {
            inputLine = localLine = l;

            CNCPoint curPosition = prevLn.ToPosition;

            FromPosition = curPosition;

            if (inputLine.Trim().StartsWith("("))
            {
            }

            //Remove line number, if presents
            RemoveLineNumber();
            //Remove comments
            RemoveComments();

            curX = curPosition.x.ToString();
            curY = curPosition.y.ToString();
            curZ = curPosition.z.ToString();

            ParseCoord();

            ProcessCommand();

            this.prev = prevLn;

            prevLn.next = this;

            LineNum = GetCurrentLineNumber();
        }
Beispiel #3
0
        public CNCPlane(CNCPoint pt1, CNCPoint pt2, CNCPoint pt3)
        {
            CNCVector vt1 = new CNCVector(pt1, pt2);
            CNCVector vt2 = new CNCVector(pt1, pt3);

            CNCVector perpVt = CNCVector.GetPerpendicularVector(vt1, vt2);

            this.a = perpVt.a;
            this.b = perpVt.b;
            this.c = perpVt.c;

            this.d = pt1.x * a + pt1.y * b + pt1.z * c;
        }
Beispiel #4
0
        public BoundingBox GetBoundingBox()
        {
            BoundingBox bbox = new BoundingBox()
            {
                XMax = -1000, XMin = 1000, YMax = -1000, YMin = 1000, ZMax = -1000, ZMin = 1000
            };
            GCodeLine curLn = this;

            while (curLn != null)
            {
                CNCPoint toPt = curLn.ToPosition;
                if (toPt.x < bbox.XMin)
                {
                    bbox.XMin = toPt.x;
                }
                if (toPt.x > bbox.XMax)
                {
                    bbox.XMax = toPt.x;
                }

                if (toPt.y < bbox.YMin)
                {
                    bbox.YMin = toPt.y;
                }
                if (toPt.y > bbox.YMax)
                {
                    bbox.YMax = toPt.y;
                }

                if (toPt.z < bbox.ZMin)
                {
                    bbox.ZMin = toPt.z;
                }
                if (toPt.z > bbox.ZMax)
                {
                    bbox.ZMax = toPt.z;
                }

                curLn = curLn.next;
            }
            return(bbox);
        }
Beispiel #5
0
        public static bool PointInTriangle(CNCPoint p, CNCPoint p0, CNCPoint p1, CNCPoint p2)
        {
            var s = p0.y * p2.x - p0.x * p2.y + (p2.y - p0.y) * p.x + (p0.x - p2.x) * p.y;
            var t = p0.x * p1.y - p0.y * p1.x + (p0.y - p1.y) * p.x + (p1.x - p0.x) * p.y;

            if ((s < 0) != (t < 0))
            {
                return(false);
            }

            var A = -p1.y * p2.x + p0.y * (p2.x - p1.x) + p0.x * (p1.y - p2.y) + p1.x * p2.y;

            if (A < 0.0)
            {
                s = -s;
                t = -t;
                A = -A;
            }
            return(s > 0 && t > 0 && (s + t) < A);
        }
Beispiel #6
0
        /// <summary>
        /// Parse X, Y, Z, F, I and J
        /// </summary>
        private void ParseCoord()
        {
            //Find if there is any x, y, z or f parameters
            Match xm = xPosR.Match(localLine);
            Match ym = yPosR.Match(localLine);
            Match zm = zPosR.Match(localLine);
            Match fm = fRateR.Match(localLine);
            Match im = iR.Match(localLine);
            Match jm = jR.Match(localLine);

            //If x parameter found
            if (xm.Success)
            {
                xPresent = true;
                //Set local x parameter
                x = xm.Value.Substring(1).Trim();
                //Set global current x
                curX = x;
                //Set IsPosition Flag
                isPosition = true;
            }
            else //set the x value to global current x
            {
                if (curX.Length > 0)
                {
                    x = curX;
                }
            }

            if (ym.Success)
            {
                yPresent   = true;
                y          = ym.Value.Substring(1).Trim();
                curY       = y;
                isPosition = true;
            }
            else
            {
                if (curY.Length > 0)
                {
                    y = curY;
                }
            }

            if (zm.Success)
            {
                zPresent   = true;
                z          = zm.Value.Substring(1).Trim();
                curZ       = z;
                isPosition = true;
            }
            else
            {
                if (curZ.Length > 0)
                {
                    z = curZ;
                }
            }

            if (x.Length == 0 || y.Length == 0 || z.Length == 0)
            {
                xDir = curXDir = -1;
                yDir = curYDir = -1;
                zDir = curZDir = -1;

                x = curX = "0";
                y = curY = "0";
                z = curZ = "0";

                FromPosition = new CNCPoint(0, 0, 0);
            }

            ToPosition = new CNCPoint(x, y, z);

            if (fm.Success)
            {
                fPresent = true;
                f        = fm.Value.Substring(1).Trim();
                curF     = f;
            }
            else
            {
                if (curF.Length > 0)
                {
                    f = curF;
                }
            }

            if (im.Success && jm.Success)
            {
                isArc = true;
            }
        }
Beispiel #7
0
 public double DistXYZ(CNCPoint pt)
 {
     return(Math.Sqrt(Math.Pow(pt.x - this.x, 2) + Math.Pow(pt.y - this.y, 2) + Math.Pow(pt.z - this.z, 2)));
 }
Beispiel #8
0
 public CNCVector(CNCPoint ptA, CNCPoint ptB)
 {
     a = ptB.x - ptA.x;
     b = ptB.y - ptA.y;
     c = ptB.z - ptA.z;
 }