Ejemplo n.º 1
0
 public plane(quaternion normal, quaternion point)
 {
     n      = new quaternion(0, normal.GetX(), normal.GetY(), normal.GetZ());
     D      = -normal.GetX() * point.GetX() - normal.GetY() * point.GetY() - normal.GetZ() * point.GetZ();
     bak    = new quaternion[3];
     bak    = this.GetThreePoints();
     bak[0] = point;
 }
Ejemplo n.º 2
0
        public plane(quaternion q1, quaternion q2, quaternion q3)//равнина през 3 точки
        {
            double A = (new matrix(3, new double[] { q1.GetY(), q1.GetZ(), 1, q2.GetY(), q2.GetZ(), 1, q3.GetY(), q3.GetZ(), 1 })).Det();
            double B = -(new matrix(3, new double[] { q1.GetX(), q1.GetZ(), 1, q2.GetX(), q2.GetZ(), 1, q3.GetX(), q3.GetZ(), 1 })).Det();
            double C = (new matrix(3, new double[] { q1.GetX(), q1.GetY(), 1, q2.GetX(), q2.GetY(), 1, q3.GetX(), q3.GetY(), 1 })).Det();

            D      = -(new matrix(3, new double[] { q1.GetX(), q1.GetY(), q1.GetZ(), q2.GetX(), q2.GetY(), q2.GetZ(), q3.GetX(), q3.GetY(), q3.GetZ() })).Det();
            n      = new quaternion(0.0, A, B, C);
            bak    = new quaternion[3];
            bak[0] = q1; bak[1] = q2; bak[2] = q3;
        }
Ejemplo n.º 3
0
 public static double[] GetScaleAutoCAD_Matrix3d(double k, quaternion B /*base*/)
 {
     return(new double[] { k, 0.0, 0.0, -B.GetX() * (k - 1.0),
                           0.0, k, 0.0, -B.GetY() * (k - 1.0),
                           0.0, 0.0, k, -B.GetZ() * (k - 1.0),
                           0.0, 0.0, 0.0, 1.0 });;
 }
Ejemplo n.º 4
0
 public double[] GetAutoCAD_Matrix3d()//***
 // Matrix3d acMat3d = new Matrix3d(ucs.GetAutoCAD_Matrix3d());
 {
     return(new double[] { ang.GetAt(1, 1), ang.GetAt(1, 2), ang.GetAt(1, 3), o.GetX(),
                           ang.GetAt(2, 1), ang.GetAt(2, 2), ang.GetAt(2, 3), o.GetY(),
                           ang.GetAt(3, 1), ang.GetAt(3, 2), ang.GetAt(3, 3), o.GetZ(),
                           0.0, 0.0, 0.0, 1.0 });
 }
Ejemplo n.º 5
0
        public quaternion IntersectWithVector(quaternion e, quaternion s)
        {
            quaternion v   = new quaternion(e - s);
            double     d   = (-n.GetX() * s.GetX() - n.GetY() * s.GetY() - n.GetZ() * s.GetZ() - D) / (n.GetX() * v.GetX() + n.GetY() * v.GetY() + n.GetZ() * v.GetZ());
            quaternion rez = new quaternion(0, d * v.GetX() + s.GetX(), d * v.GetY() + s.GetY(), d * v.GetZ() + s.GetZ());

            if (((double.IsInfinity(Math.Abs(rez.GetX())))) || ((double.IsInfinity(Math.Abs(rez.GetY())))) || ((double.IsInfinity(Math.Abs(rez.GetZ())))) ||
                double.IsNaN(rez.GetX()) || double.IsNaN(rez.GetY()) || double.IsNaN(rez.GetZ()))
            {
                rez = new quaternion(-1, 0, 0, 0);
            }
            return(rez);
        }
Ejemplo n.º 6
0
        public quaternion[] GetThreePoints(double k = 100.0)
        {
            quaternion[] rez = new quaternion[3];

            quaternion xOrt = new quaternion(0, 1, 0, 0);
            quaternion yOrt = new quaternion(0, 0, 1, 0);

            quaternion r1 = n / xOrt;
            quaternion r2 = n / yOrt;

            quaternion r3 = (r1.absV() > r2.absV()) ? r1 : r2;

            r3 = new quaternion(0, r3.GetX(), r3.GetY(), r3.GetZ());

            UCS ucs = new UCS(new quaternion(), n, r3);

            rez[0] = new quaternion();
            rez[1] = ucs.ToACS(new quaternion(0, 0, 0, k));
            rez[2] = ucs.ToACS(new quaternion(0, 0, k, 0));

            return(rez);
        }
Ejemplo n.º 7
0
 public double dist(quaternion Q)//връща разстоянието до точка Q
 {
     return((n.GetX() * Q.GetX() + n.GetY() * Q.GetY() + n.GetZ() * Q.GetZ() + D) /
            Math.Sqrt(n.GetX() * n.GetX() + n.GetY() * n.GetY() + n.GetZ() * n.GetZ()));
 }
Ejemplo n.º 8
0
 public double GetC()
 {
     return(n.GetZ());
 }
Ejemplo n.º 9
0
        public void KojtoCAD_3D_Get_Glass_Conturs_Centroid()
        {
            Database db = HostApplicationServices.WorkingDatabase;
            Editor   ed = Application.DocumentManager.MdiActiveDocument.Editor;

            Matrix3d old = ed.CurrentUserCoordinateSystem;

            ed.CurrentUserCoordinateSystem = Matrix3d.Identity;

            try
            {
                PromptKeywordOptions pop = new PromptKeywordOptions("");
                pop.AppendKeywordsToMessage = true;
                pop.AllowNone = false;
                pop.Keywords.Add("Run");
                pop.Keywords.Add("Help");
                pop.Keywords.Default = "Run";
                PromptResult res = ed.GetKeywords(pop);
                //_AcAp.Application.ShowAlertDialog(res.ToString());
                if (res.Status == PromptStatus.OK)
                {
                    switch (res.StringResult)
                    {
                    case "Run":
                        if ((container != null) && (container.Bends.Count > 0) && (container.Nodes.Count > 0) && (container.Triangles.Count > 0))
                        {
                            double     area = 0.0;
                            quaternion cen  = new quaternion();
                            foreach (WorkClasses.Triangle TR in container.Triangles)
                            {
                                Triplet <quaternion, quaternion, quaternion> pr = container.GetInnererTriangle(TR.Numer, true);

                                double ar = Math.Abs(GlobalFunctions.GetArea(pr));

                                area += ar;
                                quaternion centroid = new quaternion();
                                centroid  = (pr.First + pr.Second) / 2.0;
                                centroid  = centroid - pr.Third;
                                centroid *= (2.0 / 3.0);
                                centroid  = pr.Third + centroid;
                                centroid *= ar;
                                cen      += centroid;
                            }
                            if (area > 0.0)
                            {
                                cen /= area;
                                string title = "\nTeoretical Mesh Glass Conturs center of gravity\n------------------\n\n";
                                string mess  = string.Format("{0} total area: {1} \n Coordinate: {2:f5},{3:f5},{4:f5}", title, area,
                                                             cen.GetX(), cen.GetY(), cen.GetZ());
                                ed.WriteMessage(mess);

                                MessageBox.Show(mess, "Glass Conturs - teoretical mesh center of gravity", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            }
                        }
                        else
                        {
                            MessageBox.Show("\nData Base Empty !\n", "Range Error !", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                        break;

                    case "Help":
                        GlobalFunctions.OpenHelpHTML("http://3dsoft.blob.core.windows.net/kojtocad/html/SPOTS_CENTROID.htm");
                        break;
                    }
                }
            }
            catch (System.Exception ex)
            {
                Application.ShowAlertDialog(
                    string.Format("\nError: {0}\nStackTrace: {1}", ex.Message, ex.StackTrace));
            }
            finally { ed.CurrentUserCoordinateSystem = old; }
        }
Ejemplo n.º 10
0
        public void KojtoCAD_3D_Get_Real_3D_Centroid()
        {
            Database db  = HostApplicationServices.WorkingDatabase;
            Editor   ed  = Application.DocumentManager.MdiActiveDocument.Editor;
            Matrix3d old = ed.CurrentUserCoordinateSystem;

            ed.CurrentUserCoordinateSystem = Matrix3d.Identity;

            try
            {
                Pair <double, PromptStatus> nodeDensityPair =
                    GlobalFunctions.GetDouble(ConstantsAndSettings.nodeDensity, "\nNodes Density: ");
                if (nodeDensityPair.Second == PromptStatus.OK)
                {
                    Pair <double, PromptStatus> bendDensityPair =
                        GlobalFunctions.GetDouble(ConstantsAndSettings.bendDensity, "\nBends Density: ");
                    if (bendDensityPair.Second == PromptStatus.OK)
                    {
                        Pair <double, PromptStatus> nozzleDensityPair =
                            GlobalFunctions.GetDouble(ConstantsAndSettings.nozzleDensity, "\nEnd of Bends (Nozzle) Density: ");

                        if (nozzleDensityPair.Second == PromptStatus.OK)
                        {
                            Pair <double, PromptStatus> glassDensityPair =
                                GlobalFunctions.GetDouble(ConstantsAndSettings.glassDensity, "\nGlass Density: ");

                            if (glassDensityPair.Second == PromptStatus.OK)
                            {
                                if ((container != null) && (container.Bends.Count > 0) && (container.Nodes.Count > 0) && (container.Triangles.Count > 0))
                                {
                                    PromptKeywordOptions pKeyOpts = new PromptKeywordOptions("");
                                    pKeyOpts.Message = "\nEnter an option ";
                                    pKeyOpts.Keywords.Add("All");
                                    pKeyOpts.Keywords.Add("Glass");
                                    pKeyOpts.Keywords.Add("Mesh");
                                    pKeyOpts.Keywords.Add("Triangles");
                                    pKeyOpts.Keywords.Add("Polygons");
                                    pKeyOpts.Keywords.Add("Bends");
                                    pKeyOpts.Keywords.Add("Nodes");
                                    pKeyOpts.Keywords.Default = "All";
                                    pKeyOpts.AllowNone        = true;

                                    PromptResult pKeyRes = Application.DocumentManager.MdiActiveDocument.Editor.GetKeywords(pKeyOpts);
                                    {
                                        switch (pKeyRes.StringResult)
                                        {
                                        case "All":
                                            #region All
                                            Triplet <int, double, quaternion> POL = GetPolygonsCentroid(ref container, glassDensityPair.First);
                                            Triplet <int, double, quaternion> TRI = GetTrianglesCentroid(ref container, glassDensityPair.First);
                                            Triplet <int, double, quaternion> NOD = GetNodesCentroid(ref container, nodeDensityPair.First);
                                            Triplet <int, double, quaternion> BEN = GetBendsCentroid(ref container, bendDensityPair.First, nozzleDensityPair.First);
                                            if ((POL.First > 0) || (TRI.First > 0) || (NOD.First > 0) || (BEN.First > 0))
                                            {
                                                quaternion TEMP_Q = POL.Second * POL.Third + TRI.Second * TRI.Third + NOD.Second * NOD.Third + BEN.Second * BEN.Third;
                                                double     TEMP_V = POL.Second + TRI.Second + NOD.Second + BEN.Second;
                                                TEMP_Q /= TEMP_V;

                                                string title = "\nCenter of gravity\n------------------\n\n";
                                                string mess  = string.Format("{0} total volume: {1} \n Coordinate: {2:f5},{3:f5},{4:f5}", title, TEMP_V,
                                                                             TEMP_Q.GetX(), TEMP_Q.GetY(), TEMP_Q.GetZ());
                                                ed.WriteMessage(mess);

                                                MessageBox.Show(mess, "Center of gravity", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                            }
                                            #endregion
                                            break;

                                        case "Glass":
                                            #region Glass
                                            Triplet <int, double, quaternion> pol = GetPolygonsCentroid(ref container, glassDensityPair.First);
                                            Triplet <int, double, quaternion> tri = GetTrianglesCentroid(ref container, glassDensityPair.First);
                                            if ((pol.First > 0) || (tri.First > 0))
                                            {
                                                quaternion tempQ = pol.Second * pol.Third + tri.Second * tri.Third;
                                                double     tempV = pol.Second + tri.Second;
                                                tempQ /= tempV;

                                                string title = "\nGlass center of gravity\n------------------\n\n";
                                                string mess  = string.Format("{0} total volume: {1} \n Coordinate: {2:f5},{3:f5},{4:f5}", title, tempV,
                                                                             tempQ.GetX(), tempQ.GetY(), tempQ.GetZ());
                                                ed.WriteMessage(mess);

                                                MessageBox.Show(mess, "Glass - center of gravity", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                            }
                                            #endregion
                                            break;

                                        case "Mesh":
                                            #region Mesh
                                            Triplet <int, double, quaternion> nod = GetNodesCentroid(ref container, nodeDensityPair.First);
                                            Triplet <int, double, quaternion> ben = GetBendsCentroid(ref container, bendDensityPair.First, nozzleDensityPair.First);

                                            if ((nod.First > 0) || (ben.First > 0))
                                            {
                                                quaternion tempQ = nod.Second * nod.Third + ben.Second * ben.Third;
                                                double     tempV = nod.Second + ben.Second;
                                                tempQ /= tempV;

                                                string title = "\nMesh center of gravity\n------------------\n\n";
                                                string mess  = string.Format("{0} total volume: {1} \n Coordinate: {2:f5},{3:f5},{4:f5}", title, tempV,
                                                                             tempQ.GetX(), tempQ.GetY(), tempQ.GetZ());
                                                ed.WriteMessage(mess);

                                                MessageBox.Show(mess, "Mesh - center of gravity", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                            }
                                            #endregion
                                            break;

                                        case "Polygons":
                                            #region Polygons
                                            Triplet <int, double, quaternion> pp = GetPolygonsCentroid(ref container, glassDensityPair.First);
                                            if (pp.First > 0)
                                            {
                                                string title = "\nPolygons center of gravity\n------------------\n\n";
                                                string mess  = string.Format("{0} total volume: {1} \n Coordinate: {2:f5},{3:f5},{4:f5}", title, pp.Second,
                                                                             pp.Third.GetX(), pp.Third.GetY(), pp.Third.GetZ());
                                                ed.WriteMessage(mess);

                                                MessageBox.Show(mess, "Polygons - center of gravity", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                            }
                                            #endregion
                                            break;

                                        case "Triangles":
                                            #region trianles
                                            Triplet <int, double, quaternion> ppp = GetTrianglesCentroid(ref container, glassDensityPair.First);
                                            if (ppp.First > 0)
                                            {
                                                string title = "\nTriangless center of gravity\n------------------\n\n";
                                                string mess  = string.Format("{0} total volume: {1} \n Coordinate: {2:f5},{3:f5},{4:f5}", title, ppp.Second,
                                                                             ppp.Third.GetX(), ppp.Third.GetY(), ppp.Third.GetZ());
                                                ed.WriteMessage(mess);

                                                MessageBox.Show(mess, "Triangles - center of gravity", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                            }
                                            #endregion
                                            break;

                                        case "Bends":
                                            #region bends
                                            Triplet <int, double, quaternion> trB = GetBendsCentroid(ref container, bendDensityPair.First, nozzleDensityPair.First);
                                            if (trB.First > 0)
                                            {
                                                string title = "\nBends center of gravity\n------------------\n\n";
                                                string mess  = string.Format("{0} total volume: {1} \n Coordinate: {2:f5},{3:f5},{4:f5}", title, trB.Second,
                                                                             trB.Third.GetX(), trB.Third.GetY(), trB.Third.GetZ());
                                                ed.WriteMessage(mess);

                                                MessageBox.Show(mess, "Bends - center of gravity", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                            }
                                            #endregion
                                            break;

                                        case "Nodes":
                                            #region nodes
                                            Triplet <int, double, quaternion> tr = GetNodesCentroid(ref container, nodeDensityPair.First);
                                            if (tr.First > 0)
                                            {
                                                string title = "\nNodes center of gravity\n------------------\n\n";
                                                string mess  = string.Format("{0} total volume: {1} \n Coordinate: {2:f5},{3:f5},{4:f5}", title, tr.Second,
                                                                             tr.Third.GetX(), tr.Third.GetY(), tr.Third.GetZ());
                                                ed.WriteMessage(mess);

                                                MessageBox.Show(mess, "Nodes - center of gravity", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                            }
                                            #endregion
                                            break;
                                        }
                                    }
                                }
                                else
                                {
                                    MessageBox.Show("\nData Base Empty !\n", "Range Error !", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                }
                            }
                        }
                    }
                }//
            }
            catch { }
            finally { ed.CurrentUserCoordinateSystem = old; }
        }
Ejemplo n.º 11
0
        public void KojtoCAD_3D_Get_Teoretical_Bends_Centroid()
        {
            Database db = HostApplicationServices.WorkingDatabase;
            Editor   ed = Application.DocumentManager.MdiActiveDocument.Editor;

            Matrix3d old = ed.CurrentUserCoordinateSystem;

            ed.CurrentUserCoordinateSystem = Matrix3d.Identity;

            try
            {
                PromptKeywordOptions pop = new PromptKeywordOptions("");
                pop.AppendKeywordsToMessage = true;
                pop.AllowNone = false;
                pop.Keywords.Add("Run");
                pop.Keywords.Add("Help");
                pop.Keywords.Default = "Run";
                PromptResult res = ed.GetKeywords(pop);
                //_AcAp.Application.ShowAlertDialog(res.ToString());
                if (res.Status == PromptStatus.OK)
                {
                    switch (res.StringResult)
                    {
                    case "Run":
                        if ((container != null) && (container.Bends.Count > 0))
                        {
                            quaternion qSum_Bends_Teor = new quaternion();
                            double     mass            = 0.0;
                            foreach (WorkClasses.Bend bend in container.Bends)
                            {
                                if (!bend.IsFictive())
                                {
                                    qSum_Bends_Teor += (bend.MidPoint * bend.Length);
                                    mass            += bend.Length;
                                }
                            }
                            if (mass > 0)
                            {
                                qSum_Bends_Teor /= mass;
                                //UtilityClasses.GlobalFunctions.DrawLine(new Point3d(1000, 1000, 0), (Point3d)qSum_Bends_Real, 3);
                                string title = "\nTeoretical Mesh Bends center of gravity\n------------------\n\n";
                                string mess  = string.Format("{0} total length: {1} \n Coordinate: {2:f5},{3:f5},{4:f5}", title, mass,
                                                             qSum_Bends_Teor.GetX(), qSum_Bends_Teor.GetY(), qSum_Bends_Teor.GetZ());
                                ed.WriteMessage(mess);

                                MessageBox.Show(mess, "Bends - teoretical mesh center of gravity", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            }
                        }
                        else
                        {
                            MessageBox.Show("\nData Base Empty !\n\nMissing Bends !", "Range Error !", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                        break;

                    case "Help":
                        GlobalFunctions.OpenHelpHTML("http://3dsoft.blob.core.windows.net/kojtocad/html/MESH_CENTROID.htm");
                        break;
                    }
                }
            }
            catch (System.Exception ex)
            {
                Application.ShowAlertDialog(
                    string.Format("\nError: {0}\nStackTrace: {1}", ex.Message, ex.StackTrace));
            }
            finally { ed.CurrentUserCoordinateSystem = old; }
        }
Ejemplo n.º 12
0
        public void CNC_bends(StreamWriter outf, WorkClasses.Node node, double L, double Lp, double Ls, double R, double toolR, double gabaritX, double gabaritY, double gabaritZ)
        {
            Database db = HostApplicationServices.WorkingDatabase;
            Editor   ed = Application.DocumentManager.MdiActiveDocument.Editor;

            quaternion tempNodeNormal = node.GetNodesNormalsByNoFictiveBends(ref container);

            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                BlockTable acBlkTbl;
                acBlkTbl = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord acBlkTblRec;
                acBlkTblRec = tr.GetObject(acBlkTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;

                UCS ucs = node.CreateNodeUCS(L, ref container);
                UCS Ucs = node.CreateNodeUCS(L + Lp + Ls, ref container);

                int counter = 0;
                for (int i = 0; i < node.Bends_Numers_Array.Count; i++)
                {
                    WorkClasses.Bend b = container.Bends[node.Bends_Numers_Array[i]];
                    if (b.IsFictive())
                    {
                        continue;
                    }
                    outf.WriteLine(String.Format("(BAR {0} - PRYT NOMER {1})", counter + 1, b.Numer + 1));
                    outf.WriteLine();

                    //---------------------
                    quaternion bendNormal    = b.Normal - b.MidPoint;
                    plane      gabaritTOP    = new plane(ucs.ToACS(new quaternion(0, 10, 0, gabaritZ / 2.0)), ucs.ToACS(new quaternion(0, 100, 0, gabaritZ / 2.0)), ucs.ToACS(new quaternion(0, 0, 10, gabaritZ / 2.0)));
                    plane      gabaritBottom = new plane(ucs.ToACS(new quaternion(0, 10, 0, -gabaritZ / 2.0)), ucs.ToACS(new quaternion(0, 100, 0, -gabaritZ / 2.0)), ucs.ToACS(new quaternion(0, 0, 10, -gabaritZ / 2.0)));
                    quaternion Q1            = gabaritTOP.IntersectWithVector((b.MidPoint + b.Start) / 2.0, (b.MidPoint + b.Start) / 2.0 + bendNormal);
                    quaternion Q2            = gabaritTOP.IntersectWithVector(b.MidPoint, b.Normal);
                    Q1 = ucs.FromACS(Q1);
                    Q2 = ucs.FromACS(Q2);
                    complex cQ1     = new complex(Q1.GetX(), Q1.GetY());
                    complex cQ2     = new complex(Q2.GetX(), Q2.GetY());
                    matrix  Int_Mat = Common.IntersectCircleAndLine(R, cQ1, cQ2);
                    if (Int_Mat.GetAt(0, 4) < 0) /*ERRROR*/ return {
                        ;
                    }
                    complex    iP1       = new complex(Int_Mat.GetAt(0, 0), Int_Mat.GetAt(0, 1));
                    complex    iP2       = new complex(Int_Mat.GetAt(0, 2), Int_Mat.GetAt(0, 3));
                    complex    iP        = ((cQ2 - iP1).abs() < (cQ2 - iP2).abs()) ? iP1 : iP2;
                    quaternion iQ        = ucs.ToACS(new quaternion(0.0, iP.real(), iP.imag(), gabaritZ / 2.0));
                    quaternion cenTOP    = iQ;// gabaritTOP.IntersectWithVector(iQ, iQ + bendNormal);
                    quaternion cenBottom = gabaritBottom.IntersectWithVector(iQ, iQ + bendNormal);
                    Q2 = ucs.ToACS(Q2);
                    quaternion outTOP = Q2 - iQ; quaternion inTOP = iQ - Q2;
                    outTOP /= outTOP.abs(); inTOP /= inTOP.abs();
                    outTOP *= toolR; inTOP *= toolR;
                    outTOP  = iQ + outTOP; inTOP = iQ + inTOP;

                    // MessageBox.Show(String.Format("{0},{1},{2}\n{3},{4},{5}\n{6},{7},{8}",
                    //iQ.GetX(), iQ.GetY(), iQ.GetZ(), cenTOP.GetX(), cenTOP.GetY(), cenTOP.GetZ(), cenBottom.GetX(), cenBottom.GetY(), cenBottom.GetZ()));
                    //--------------------------
                    double     gabaritR   = Math.Sqrt(gabaritX * gabaritX / 4.0 + gabaritY * gabaritY / 4.0);
                    matrix     gabaritMat = Common.IntersectCircleAndLine(gabaritR, cQ1, cQ2);
                    complex    gabaritP1  = new complex(gabaritMat.GetAt(0, 0), gabaritMat.GetAt(0, 1));
                    complex    gabaritP2  = new complex(gabaritMat.GetAt(0, 2), gabaritMat.GetAt(0, 3));
                    complex    gabaritP   = ((cQ2 - gabaritP1).abs() < (cQ2 - gabaritP2).abs()) ? gabaritP1 : gabaritP2;
                    quaternion gabaritQ   = ucs.ToACS(new quaternion(0.0, gabaritP.real(), gabaritP.imag(), gabaritZ / 2.0));
                    //---------------------

                    bool bp = ((node.Position - b.Start).abs() < (node.Position - b.End).abs()) ? true : false;//kой край на реброто е във възела
                    Pair <quaternion, quaternion> bendAxe = (bp == true) ?
                                                            new Pair <quaternion, quaternion>(ucs.FromACS(b.Start), ucs.FromACS(b.End)) :
                                                            new Pair <quaternion, quaternion>(ucs.FromACS(b.End), ucs.FromACS(b.Start));

                    Pair <quaternion, quaternion> pa = new Pair <quaternion, quaternion>(ucs.FromACS(b.MidPoint), ucs.FromACS(b.Normal));
                    quaternion ucsOriginDescriptor   = new quaternion();
                    cenTOP   = ucs.FromACS(cenTOP); cenBottom = ucs.FromACS(cenBottom); inTOP = ucs.FromACS(inTOP); outTOP = ucs.FromACS(outTOP);
                    gabaritQ = ucs.FromACS(gabaritQ);
                    //  double test = Math.Sqrt(cenTOP.GetX() * cenTOP.GetX() + cenTOP.GetY() * cenTOP.GetY());
                    // MessageBox.Show(test.ToString());


                    double baseAng = 0.0;
                    if (((b.Normal - b.MidPoint) / (tempNodeNormal - node.Position)).absV() < Constants.zero_dist)
                    {
                        outf.WriteLine(String.Format("#110={0:f4}(ALPHA-OS C)", 0.0));
                        outf.WriteLine(String.Format("#111 = {0:f4} (BETHA-OS B)", 0.0));
                        outf.WriteLine(String.Format("#112 = {0:f4} (DELTA X-G52 X)", 0.0));
                        outf.WriteLine(String.Format("#113 = {0:f4} (DELTA Z-G52 X)", 0.0));

                        Pair <complex, complex> benAxeXY = new Pair <complex, complex>(
                            new complex(bendAxe.First.GetX(), bendAxe.First.GetY()), new complex(bendAxe.Second.GetX(), bendAxe.Second.GetY()));
                        matrix Int_M    = Common.IntersectCircleAndLine(R, benAxeXY.First, benAxeXY.Second);
                        double baseAng2 = (benAxeXY.Second - benAxeXY.First).arg();
                        if (baseAng2 > Math.PI)
                        {
                            baseAng2 = baseAng2 - 2 * Math.PI;
                        }

                        outf.WriteLine(String.Format("#114 = {0:f4} (GAMMA R-G68)", baseAng2 * 180.0 / Math.PI));

                        outf.WriteLine(String.Format("#115 = {0:f4} (OBRABOTKA NAD Z=0)", gabaritZ / 2.0 + 5.0));
                        outf.WriteLine(String.Format("#116 = {0:f4} (OBRABOTKA POD Z=0)", -gabaritZ / 2.0 - 2.0));
                    }
                    else
                    {
                        quaternion nB1 = ucs.FromACS(b.Normal);
                        quaternion nB2 = ucs.FromACS(b.MidPoint);
                        complex    cN1 = new complex(nB1.GetX(), nB1.GetY());
                        complex    cN2 = new complex(nB2.GetX(), nB2.GetY());
                        line2d     projectTo_ucsXY_Line = new line2d(cN1, cN2);

                        complex normalTo_projectTo_ucsXY_Line = new complex(projectTo_ucsXY_Line.A, projectTo_ucsXY_Line.B);
                        normalTo_projectTo_ucsXY_Line /= normalTo_projectTo_ucsXY_Line.abs();
                        normalTo_projectTo_ucsXY_Line *= -1.0;

                        baseAng = normalTo_projectTo_ucsXY_Line.arg();
                        if (baseAng > Math.PI)
                        {
                            baseAng = baseAng - 2 * Math.PI;
                        }

                        outf.WriteLine(String.Format("#110={0:f4}(ALPHA-OS C)", -((-baseAng + Math.PI / 2.0) * 180.0 / Math.PI)));

                        pa.First.set_rotateAroundAxe(new quaternion(0, 0, 0, 100.0), -baseAng + Math.PI / 2.0);
                        pa.Second.set_rotateAroundAxe(new quaternion(0, 0, 0, 100.0), -baseAng + Math.PI / 2.0);

                        bendAxe.First.set_rotateAroundAxe(new quaternion(0, 0, 0, 100.0), -baseAng + Math.PI / 2.0);
                        bendAxe.Second.set_rotateAroundAxe(new quaternion(0, 0, 0, 100.0), -baseAng + Math.PI / 2.0);

                        ucsOriginDescriptor.set_rotateAroundAxe(new quaternion(0, 0, 0, 100.0), -baseAng + Math.PI / 2.0);

                        cenTOP.set_rotateAroundAxe(new quaternion(0, 0, 0, 100.0), -baseAng + Math.PI / 2.0);
                        cenBottom.set_rotateAroundAxe(new quaternion(0, 0, 0, 100.0), -baseAng + Math.PI / 2.0);
                        inTOP.set_rotateAroundAxe(new quaternion(0, 0, 0, 100.0), -baseAng + Math.PI / 2.0);
                        outTOP.set_rotateAroundAxe(new quaternion(0, 0, 0, 100.0), -baseAng + Math.PI / 2.0);
                        gabaritQ.set_rotateAroundAxe(new quaternion(0, 0, 0, 100.0), -baseAng + Math.PI / 2.0);

                        pa                  = new Pair <quaternion, quaternion>(ucs.ToACS(pa.First), ucs.ToACS(pa.Second));
                        bendAxe             = new Pair <quaternion, quaternion>(ucs.ToACS(bendAxe.First), ucs.ToACS(bendAxe.Second));
                        ucsOriginDescriptor = ucs.ToACS(ucsOriginDescriptor);
                        cenTOP              = ucs.ToACS(cenTOP); cenBottom = ucs.ToACS(cenBottom); inTOP = ucs.ToACS(inTOP); outTOP = ucs.ToACS(outTOP);
                        gabaritQ            = ucs.ToACS(gabaritQ);

                        pa                  = new Pair <quaternion, quaternion>(Ucs.FromACS(pa.First), Ucs.FromACS(pa.Second));
                        bendAxe             = new Pair <quaternion, quaternion>(Ucs.FromACS(bendAxe.First), Ucs.FromACS(bendAxe.Second));
                        ucsOriginDescriptor = Ucs.FromACS(ucsOriginDescriptor);
                        cenTOP              = Ucs.FromACS(cenTOP); cenBottom = Ucs.FromACS(cenBottom); inTOP = Ucs.FromACS(inTOP); outTOP = Ucs.FromACS(outTOP);
                        gabaritQ            = Ucs.FromACS(gabaritQ);

                        quaternion normal = (pa.Second - pa.First) * 1000.0;
                        pa = new Pair <quaternion, quaternion>(pa.First, pa.First + normal);
                        double k = (pa.Second.GetX() < pa.First.GetX()) ? 1.0 : -1.0;

                        double ang = (pa.Second - pa.First).angTo(new quaternion(0, 0, 0, 100));
                        ang *= k;
                        outf.WriteLine(String.Format("#111 = {0:f4} (BETHA-OS B)", ang * 180.0 / Math.PI));

                        pa.First.set_rotateAroundAxe(new quaternion(0, 0, 100.0, 0.0), ang);
                        pa.Second.set_rotateAroundAxe(new quaternion(0, 0, 100.0, 0.0), ang);

                        bendAxe.First.set_rotateAroundAxe(new quaternion(0, 0, 100.0, 0.0), ang);
                        bendAxe.Second.set_rotateAroundAxe(new quaternion(0, 0, 100.0, 0.0), ang);

                        ucsOriginDescriptor.set_rotateAroundAxe(new quaternion(0, 0, 100.0, 0.0), ang);

                        cenTOP.set_rotateAroundAxe(new quaternion(0, 0, 100.0, 0.0), ang);
                        cenBottom.set_rotateAroundAxe(new quaternion(0, 0, 100.0, 0.0), ang);
                        inTOP.set_rotateAroundAxe(new quaternion(0, 0, 100.0, 0.0), ang);
                        outTOP.set_rotateAroundAxe(new quaternion(0, 0, 100.0, 0.0), ang);
                        gabaritQ.set_rotateAroundAxe(new quaternion(0, 0, 100.0, 0.0), ang);

                        pa                  = new Pair <quaternion, quaternion>(Ucs.ToACS(pa.First), Ucs.ToACS(pa.Second));
                        bendAxe             = new Pair <quaternion, quaternion>(Ucs.ToACS(bendAxe.First), Ucs.ToACS(bendAxe.Second));
                        ucsOriginDescriptor = Ucs.ToACS(ucsOriginDescriptor);
                        cenTOP              = Ucs.ToACS(cenTOP); cenBottom = Ucs.ToACS(cenBottom); inTOP = Ucs.ToACS(inTOP); outTOP = Ucs.ToACS(outTOP);
                        gabaritQ            = Ucs.ToACS(gabaritQ);

                        pa                  = new Pair <quaternion, quaternion>(ucs.FromACS(pa.First), ucs.FromACS(pa.Second));
                        bendAxe             = new Pair <quaternion, quaternion>(ucs.FromACS(bendAxe.First), ucs.FromACS(bendAxe.Second));
                        ucsOriginDescriptor = ucs.FromACS(ucsOriginDescriptor);
                        cenTOP              = ucs.FromACS(cenTOP); cenBottom = ucs.FromACS(cenBottom); inTOP = ucs.FromACS(inTOP); outTOP = ucs.FromACS(outTOP);
                        gabaritQ            = ucs.FromACS(gabaritQ);
                        outf.WriteLine(String.Format("#112 = {0:f4} (DELTA X-G52 X)", ucsOriginDescriptor.GetX()));
                        outf.WriteLine(String.Format("#113 = {0:f4} (DELTA Z-G52 X)", ucsOriginDescriptor.GetZ()));
                        double backX = ucsOriginDescriptor.GetX();
                        double backZ = ucsOriginDescriptor.GetZ();

                        quaternion moveQ = new quaternion(0, -backX, 0.0, -backZ);
                        pa                   = new Pair <quaternion, quaternion>(pa.First + moveQ, pa.Second + moveQ);
                        bendAxe              = new Pair <quaternion, quaternion>(bendAxe.First + moveQ, bendAxe.Second + moveQ);
                        ucsOriginDescriptor += moveQ;
                        cenTOP              += moveQ; cenBottom += moveQ; inTOP += moveQ; outTOP += moveQ;
                        gabaritQ            += moveQ;

                        Pair <complex, complex> benAxeXY = new Pair <complex, complex>(
                            new complex(bendAxe.First.GetX(), bendAxe.First.GetY()), new complex(bendAxe.Second.GetX(), bendAxe.Second.GetY()));
                        matrix Int_M = Common.IntersectCircleAndLine(R, benAxeXY.First, benAxeXY.Second);

                        complex Int_P1   = new complex(Int_M.GetAt(0, 0), Int_M.GetAt(0, 1));
                        complex Int_P2   = new complex(Int_M.GetAt(0, 2), Int_M.GetAt(0, 3));
                        complex Int_P    = ((benAxeXY.Second - Int_P1).abs() < (benAxeXY.Second - Int_P2).abs()) ? Int_P1 : Int_P2;
                        double  baseAng2 = (benAxeXY.Second - benAxeXY.First).arg();
                        if (baseAng2 > Math.PI)
                        {
                            baseAng2 = baseAng2 - 2 * Math.PI;
                        }

                        outf.WriteLine(String.Format("#114 = {0:f4} (GAMMA R-G68)", baseAng2 * 180.0 / Math.PI));

                        //----------------------
                        pa                  = new Pair <quaternion, quaternion>(ucs.ToACS(pa.First), ucs.ToACS(pa.Second));
                        bendAxe             = new Pair <quaternion, quaternion>(ucs.ToACS(bendAxe.First), ucs.ToACS(bendAxe.Second));
                        ucsOriginDescriptor = ucs.ToACS(ucsOriginDescriptor);
                        cenTOP              = ucs.ToACS(cenTOP); cenBottom = ucs.ToACS(cenBottom); inTOP = ucs.ToACS(inTOP); outTOP = ucs.ToACS(outTOP);
                        gabaritQ            = ucs.ToACS(gabaritQ);
                        quaternion gabaritB = gabaritQ + cenBottom - cenTOP;
                        quaternion inBottom = inTOP + cenBottom - cenTOP;

                        double positiveZ = (ucs.FromACS(gabaritQ).GetZ() > ucs.FromACS(inTOP).GetZ()) ? ucs.FromACS(gabaritQ).GetZ() + 5.0 : ucs.FromACS(inTOP).GetZ() + 5.0;
                        double negativeZ = (ucs.FromACS(gabaritB).GetZ() < ucs.FromACS(inBottom).GetZ()) ? ucs.FromACS(gabaritB).GetZ() - 2.0 : ucs.FromACS(inBottom).GetZ() - 2.0;

                        outf.WriteLine(String.Format("#115 = {0:f4} (OBRABOTKA NAD Z=0)", positiveZ));
                        outf.WriteLine(String.Format("#116 = {0:f4} (OBRABOTKA POD Z=0)", negativeZ));

                        #region draw test1

                        /*
                         * Line LL = new Line((Point3d)pa.First, (Point3d)pa.Second);
                         * LL.ColorIndex = 1;
                         * acBlkTblRec.AppendEntity(LL);
                         * tr.AddNewlyCreatedDBObject(LL, true);
                         *
                         * Line LLL = new Line((Point3d)inTOP, (Point3d)outTOP);
                         * LLL.ColorIndex = 1;
                         * acBlkTblRec.AppendEntity(LLL);
                         * tr.AddNewlyCreatedDBObject(LLL, true);
                         *
                         *
                         * Line LLLL = new Line((Point3d)cenTOP, (Point3d)cenBottom);
                         * LLLL.ColorIndex = 1;
                         * acBlkTblRec.AppendEntity(LLLL);
                         * tr.AddNewlyCreatedDBObject(LLLL, true);
                         *
                         * Line LLLLL = new Line((Point3d)bendAxe.First, (Point3d)bendAxe.Second);
                         * LLLLL.ColorIndex = 1;
                         * acBlkTblRec.AppendEntity(LLLLL);
                         * tr.AddNewlyCreatedDBObject(LLLLL, true);
                         *
                         * Line PP = new Line((Point3d)outTOP, (Point3d)gabaritQ);
                         * PP.ColorIndex = 2;
                         * acBlkTblRec.AppendEntity(PP);
                         * tr.AddNewlyCreatedDBObject(PP, true);
                         *
                         * Line PPP = new Line((Point3d)gabaritB, (Point3d)gabaritQ);
                         * PPP.ColorIndex = 2;
                         * acBlkTblRec.AppendEntity(PPP);
                         * tr.AddNewlyCreatedDBObject(PPP, true);
                         *
                         * Line PPPP = new Line((Point3d)inBottom, (Point3d)inTOP);
                         * PPPP.ColorIndex = 2;
                         * acBlkTblRec.AppendEntity(PPPP);
                         * tr.AddNewlyCreatedDBObject(PPPP, true);
                         */
                        #endregion
                    }

                    outf.WriteLine("G65P1401");
                    outf.WriteLine("M1");
                    outf.WriteLine();

                    counter++;
                }

                //outf.WriteLine(String.Format("G43{0}", G43H));
                tr.Commit();
                Application.DocumentManager.MdiActiveDocument.Editor.UpdateScreen();
            }