예제 #1
0
        /// <summary>
        /// Detects the start direction of an arc
        /// </summary>
        /// <param name="whereAmINow">array of arrays holding the most recent points</param>
        /// <returns></returns>
        double DetectDirectioninArc(double[][] whereAmINow)
        {
            double destinationAngle = whereAmINow[0][4]; double directionofArcCenter;

            if (whereAmINow[0][6] == 2)  //turn clockwise
            {
                directionofArcCenter = destinationAngle - 90;
                if (directionofArcCenter < 0)
                {
                    directionofArcCenter += 360;
                }
            }
            else  //Turn counter clockwise
            {
                directionofArcCenter = destinationAngle + 90;
                if (directionofArcCenter >= 360)
                {
                    directionofArcCenter -= 360;
                }
            }
            //holds position of the center of the arc, relative to the end point
            double angle = 0;
            {   //Finds cosV
                if (directionofArcCenter <= 90)
                {
                    angle = 90 - directionofArcCenter;
                }
                else if (directionofArcCenter <= 180)
                {
                    angle = directionofArcCenter - 90;
                }
                else if (directionofArcCenter <= 270)
                {
                    angle = 270 - directionofArcCenter;
                }
                else if (directionofArcCenter <= 360)
                {
                    angle = directionofArcCenter - 270;
                }
                angle = angle * (Math.PI / 180);
                double t = Math.Sin(angle);
            }
            double xArcCenter = Math.Abs(Math.Sin(angle) * whereAmINow[0][5]);
            double yArcCenter = Math.Abs(Math.Cos(angle) * whereAmINow[0][5]);

            if (directionofArcCenter > 180)
            {
                yArcCenter = -yArcCenter;
            }
            if (directionofArcCenter > 90 && directionofArcCenter < 270)
            {
                xArcCenter = -xArcCenter;
            }
            xArcCenter += whereAmINow[0][0]; yArcCenter += whereAmINow[0][1];
            double[] s = new double[2] {
                xArcCenter, yArcCenter
            };
            destinationAngle = SharedMethods.CheckDirection(s, whereAmINow[1]);
            if (whereAmINow[0][6] == 2)
            {
                destinationAngle -= 90;
            }
            else
            {
                destinationAngle += 90;
            }
            if (destinationAngle < 0)
            {
                destinationAngle += 360;
            }
            else if (destinationAngle > 360)
            {
                destinationAngle -= 360;
            }
            return(destinationAngle);
        }
예제 #2
0
        NCFile DetectLongArc(NCFile file)
        {
            int i = 0; double[][] whereAmINow = new double[5][]; //[][0]=X, [][1]=Y, [][2]=Z, [][3]=F, [][4]=A, [][5]=R, [][6]=movement type, [][7]=line number in the file

            while (i < file.AmountLines())
            {
                if (file.CheckLineBlock(i))
                {
                    string line = file.GetCode(i);
                    whereAmINow = GetLocation(line, whereAmINow, i);
                    if (line.Contains("A"))
                    {
                        double startA = SharedMethods.DetectStartingDirectionOfArc(whereAmINow);
                        double endA   = GetValue(line, 'A');
                        double changed;
                        if (whereAmINow[0][6] == 2)
                        {   // turn clockwise
                            changed = startA - endA;
                            if (changed < 0)
                            {
                                changed = startA + (360 - endA);
                            }
                        }
                        else
                        {   // turn counter clockwise
                            changed = endA - startA;
                            if (changed < 0)
                            {
                                changed = endA + (360 - startA);
                            }
                        }
                        string newLine = ""; int blockNumber = file.GetLineBlock(i);
                        if (changed > 359)
                        {
                            blockNumber -= 3;
                        }                                        //      changes starting block number to correspond to amount of new lines being added
                        else if (changed > 269)
                        {
                            blockNumber -= 2;
                        }                                            //  infront of the line being examined
                        else if (changed > 179)
                        {
                            blockNumber -= 1;
                        }

                        double[] d = SharedMethods.DetectArcSenter(whereAmINow);//[0]=x, [1]=y
                        if (changed > 179)
                        {
                            while (true)
                            {
                                if (changed > 179)
                                {
                                    double x = d[0]; double y = d[1]; double newAngle;
                                    if (whereAmINow[0][6] == 2)
                                    {   // turn clockwise
                                        if (startA <= 90)
                                        {
                                            newAngle = 0; y += whereAmINow[0][5];
                                        }
                                        else if (startA <= 180)
                                        {
                                            newAngle = 90; x -= whereAmINow[0][5];
                                        }
                                        else if (startA <= 270)
                                        {
                                            newAngle = 180; y -= whereAmINow[0][5];
                                        }
                                        else
                                        {
                                            newAngle = 270; x += whereAmINow[0][5];
                                        }
                                    }
                                    else
                                    {   // turn counter clockwise
                                        if (startA >= 270)
                                        {
                                            newAngle = 0; y -= whereAmINow[0][5];
                                        }
                                        else if (startA >= 180)
                                        {
                                            newAngle = 270; x -= whereAmINow[0][5];
                                        }
                                        else if (startA >= 90)
                                        {
                                            newAngle = 180; y += whereAmINow[0][5];
                                        }
                                        else
                                        {
                                            newAngle = 90; x += whereAmINow[0][5];
                                        }
                                    }
                                    newLine = newLine + "N" + blockNumber + " G0" + Convert.ToInt32(whereAmINow[0][6]) + " X" + file.DoubleToString(x) + " Y" +
                                              file.DoubleToString(y) + " A" + file.DoubleToString(newAngle) + " R" + file.DoubleToString(whereAmINow[0][5]);
                                    if (!newLine.Contains("F"))
                                    {
                                        newLine = newLine + " F" + file.DoubleToString(whereAmINow[0][3]);
                                    }
                                    newLine = newLine + "\n";
                                    blockNumber++; changed -= 90;
                                    startA = newAngle;
                                }
                                else
                                {
                                    string oldLine = "N" + Convert.ToString(file.GetLineBlock(i)) + " X" + file.DoubleToString(whereAmINow[0][0]) + " Y" + file.DoubleToString(whereAmINow[0][1])
                                                     + " A" + file.DoubleToString(whereAmINow[0][4]) + " R" + file.DoubleToString(whereAmINow[0][5]);
                                    newLine = newLine + oldLine;
                                    file.UpdateLine(i, newLine);
                                    break;
                                }
                            }
                        }
                    }
                }
                i++;
            }
            file.RebuildLines();
            return(file);
        }