示例#1
0
        public static List <int> FindSelfIntersectPline(Polyline polyline)
        {
            List <int> resultPts = new List <int>();

            DBObjectCollection entities = new DBObjectCollection();

            polyline.Explode(entities);

            for (int i = 0; i < entities.Count; ++i)
            {
                for (int j = i + 1; j < entities.Count; ++j)
                {
                    Curve curve1 = entities[i] as Curve;
                    Curve curve2 = entities[j] as Curve;

                    Autodesk.AutoCAD.Geometry.Point3dCollection points = new Autodesk.AutoCAD.Geometry.Point3dCollection();
                    curve1.IntersectWith(
                        curve2,
                        Intersect.OnBothOperands,
                        points,
                        IntPtr.Zero,
                        IntPtr.Zero);

                    foreach (Point3d point in points)
                    {
                        // Make a check to skip the start/end points
                        // since they are connected vertices
                        if (point == curve1.StartPoint ||
                            point == curve1.EndPoint)
                        {
                            if (point == curve2.StartPoint ||
                                point == curve2.EndPoint)
                            {
                                // If two consecutive segments, then skip
                                if (j == i + 1)
                                {
                                    continue;
                                }
                            }
                        }

                        resultPts.Add(j);
                    }
                }

                // Need to be disposed explicitely
                // since entities are not DB resident
                entities[i].Dispose();
            }
            return(resultPts);
        }
        public static List<int> FindSelfIntersectPline(Polyline polyline)
        {
            List<int> resultPts = new List<int>();

            DBObjectCollection entities = new DBObjectCollection();
            polyline.Explode(entities);

            for (int i = 0; i < entities.Count; ++i)
            {
                for (int j = i + 1; j < entities.Count; ++j)
                {
                    Curve curve1 = entities[i] as Curve;
                    Curve curve2 = entities[j] as Curve;

                    Autodesk.AutoCAD.Geometry.Point3dCollection points = new Autodesk.AutoCAD.Geometry.Point3dCollection();
                    curve1.IntersectWith(
                        curve2,
                        Intersect.OnBothOperands,
                        points,
                        IntPtr.Zero,
                        IntPtr.Zero);

                    foreach (Point3d point in points)
                    {
                        // Make a check to skip the start/end points
                        // since they are connected vertices
                        if (point == curve1.StartPoint ||
                            point == curve1.EndPoint)
                        {
                            if (point == curve2.StartPoint ||
                                point == curve2.EndPoint)
                            {
                                // If two consecutive segments, then skip
                                if (j == i + 1)
                                {
                                    continue;
                                }
                            }
                        }

                        resultPts.Add(j);
                    }
                }

                // Need to be disposed explicitely
                // since entities are not DB resident
                entities[i].Dispose();
            }
            return resultPts;
        }
示例#3
0
        public static Point3d?GetNormalPointEx(this Polyline sourceLine, Point3d point, Polyline distanceLine)
        {
            Autodesk.AutoCAD.Geometry.Vector3d normal = sourceLine.GetFirstDerivative(point);
            normal = normal.GetPerpendicularVector();

            Autodesk.AutoCAD.Geometry.Point3dCollection intersects = new Autodesk.AutoCAD.Geometry.Point3dCollection();
            distanceLine.IntersectWith(new Line(point, new Autodesk.AutoCAD.Geometry.Point3d(point.X + normal.X, point.Y + normal.Y, 0d)), Intersect.ExtendBoth, new Autodesk.AutoCAD.Geometry.Plane(), intersects, new IntPtr(1), new IntPtr(0));
            if (intersects.Count == 0)
            {
                return(null);
            }
            else
            {
                return(intersects[0]);
            }
        }
示例#4
0
        private static List <AcadGeo.Point3d> ParseLine(AcadDB.ObjectId id, List <AcadDB.ObjectId> ids)
        {
            List <AcadGeo.Point3d> pnts = new List <AcadGeo.Point3d>();

            using (AcadDB.Transaction tr = AcadFuncs.GetActiveDB().TransactionManager.StartTransaction())
            {
                AcadDB.Entity ent = tr.GetObject(id, AcadDB.OpenMode.ForRead) as AcadDB.Entity;
                if (!(ent is AcadDB.Line))
                {
                    return(pnts);
                }

                AcadDB.Line line = ent as AcadDB.Line;
                pnts.Add(line.StartPoint);
                pnts.Add(line.EndPoint);

                foreach (var tmp_id in ids)
                {
                    if (id == tmp_id)
                    {
                        continue;
                    }

                    AcadDB.Entity             tmp_ent          = tr.GetObject(tmp_id, AcadDB.OpenMode.ForRead) as AcadDB.Entity;
                    AcadGeo.Point3dCollection intersected_pnts = new AcadGeo.Point3dCollection();
                    line.IntersectWith(tmp_ent, AcadDB.Intersect.OnBothOperands, intersected_pnts, (IntPtr)0, (IntPtr)0);

                    for (int i = 0; i < intersected_pnts.Count; i++)
                    {
                        if (intersected_pnts[i].IsEqualTo(line.StartPoint) || intersected_pnts[i].IsEqualTo(line.EndPoint))
                        {
                            continue;
                        }

                        pnts.Add(intersected_pnts[i]);
                    }
                }
            }

            pnts.Sort((x, y) => x.DistanceTo(pnts.First()).CompareTo(y.DistanceTo(pnts.First())));
            pnts = pnts.Distinct().ToList();
            return(pnts);
        }
示例#5
0
        private Featureline GetCorridorFeatureline(CivilDB.CorridorFeatureLine featureline = null, bool isOffset = false)
        {
            // construct the 3d polyline
            var collection = new Acad.Point3dCollection();

            foreach (var point in featureline.FeatureLinePoints)
            {
                collection.Add(point.XYZ);
            }
            var polyline = new Polyline3d(Poly3dType.SimplePoly, collection, false);

            // create featureline
            var _featureline = new Featureline();

            _featureline.baseCurve   = PolylineToSpeckle(polyline);
            _featureline.name        = featureline.CodeName;
            _featureline.units       = ModelUnits;
            _featureline["isOffset"] = isOffset;

            return(_featureline);
        }
示例#6
0
        public static bool GetData(Db.ObjectId ObjectId)
        {
            SettingsParser settings = SettingsParser.getInstance();

            Db.Database acCurDb = App.Application.DocumentManager.MdiActiveDocument.Database;

            using (Db.Transaction acTrans = acCurDb.TransactionManager.StartOpenCloseTransaction())
            {
                Db.Polyline acPLine = acTrans.GetObject(ObjectId, Db.OpenMode.ForRead) as Db.Polyline;

                //Блокируем повторный выбор линии
                if (curveDict.FirstOrDefault(s => s.ObjId == ObjectId) == null)
                {
                    Curve crv = new Curve(ObjectId);
                    crv.Number     = settings.startNumberCurve;
                    crv.Area       = round(acPLine.Area, settings.areaTolerance);
                    crv.AreaOutput = round(acPLine.Area * settings.allAreaTolerance, settings.coordinateTolerance);

                    settings.startNumberCurve++;

                    if (pointDict.Count > 0)
                    {
                        settings.startNumberPoint = pointDict.Count;
                    }


                    int countVertix = acPLine.NumberOfVertices;

                    for (int i = 0; i < countVertix; i++)
                    {
                        Gem.Point2d pt = acPLine.GetPoint2dAt(i);

                        int iMin = (i == 0) ? iMin = countVertix - 1 : iMin = i - 1;
                        int iMax = (i == countVertix - 1) ? iMax = 0 : iMax = i + 1;

                        //Поучаю все три точки угла


                        Gem.Point3d ptO = new Gem.Point3d(acPLine.GetPoint2dAt(i).X,
                                                          acPLine.GetPoint2dAt(i).Y, 0);
                        Gem.Point3d ptMin = new Gem.Point3d(acPLine.GetPoint2dAt(iMin).X,
                                                            acPLine.GetPoint2dAt(iMin).Y, 0);
                        Gem.Point3d ptMax = new Gem.Point3d(acPLine.GetPoint2dAt(iMax).X,
                                                            acPLine.GetPoint2dAt(iMax).Y, 0);

                        Gem.Vector3d vMin = ptO.GetVectorTo(ptMin);
                        Gem.Vector3d vMax = ptO.GetVectorTo(ptMax);

                        Gem.Vector3d vNormaliseMin = vMin / vMin.Length;
                        Gem.Vector3d vNormaliseMax = vMax / vMax.Length;

                        Gem.Vector3d vNormalise = vNormaliseMin + vNormaliseMax;
                        vNormalise = vNormalise / vNormalise.Length;

                        //Тут нужно проверять, попадает ли точка нормализованного вектора внутрь фигуры или наружу
                        using (Db.Ray cl = new Db.Ray())
                        {
                            cl.BasePoint = ptO + vNormalise;
                            cl.UnitDir   = vNormalise;
                            Gem.Point3dCollection pnt3dCol = new Gem.Point3dCollection();
                            acPLine.IntersectWith(cl, Db.Intersect.OnBothOperands, pnt3dCol, IntPtr.Zero, IntPtr.Zero);
                            if ((pnt3dCol.Count % 2) != 0)
                            {
                                vNormalise = vNormalise * (-1);
                            }
                        }

                        int namb = 0; //Номер вершины
                        if (pointDict.FirstOrDefault(s => s.IsEqualTo(pt, settings.coordinateTolerance)) == null)
                        {
                            Point pnt = new Point(round(pt.X, settings.coordinateTolerance),
                                                  round(pt.Y, settings.coordinateTolerance),
                                                  settings.startNumberPoint);

                            //Добавляем нормализованный вектор биссектриссы угла
                            pnt.vNormalise = vNormalise;
                            //Добавляем в список точек
                            pointDict.Add(pnt);
                            //Добавляем в кривую
                            crv.Vertixs.Add(pnt);

                            namb = settings.startNumberPoint;
                            settings.startNumberPoint++;
                        }
                        else
                        {
                            //Добавляем в список вершин уже обраотанную точку
                            crv.Vertixs.Add(pointDict.FirstOrDefault(s => s.IsEqualTo(pt, settings.coordinateTolerance)));
                        }
                    }

                    //Добавляем в список линий
                    curveDict.Add(crv);
                    //Вывожу данные линии в чертеж
                    View.TextToDwg(crv);
                    //View.AddText(crv.textPoint(), $"{crv.Number} \\P S={crv.Area} кв.м.");
                }
                acTrans.Commit();
            }
            return(true);
        }