Пример #1
0
        ///<summary>
        /// Get the centroid of a Region.
        ///</summary>
        ///<param name="cur">An optional curve used to define the region.</param>
        ///<returns>A nullable Point3d containing the centroid of the Region.</returns>
        public static _AcGe.Point3d? GetCentroid(this _AcDb.Region reg, _AcDb.Curve cur = null)
        {
            if (cur == null)
            {
                var idc = new _AcDb.DBObjectCollection();
                reg.Explode(idc);
                if (idc.Count == 0)
                {
                    return(null);
                }
                cur = idc[0] as _AcDb.Curve;
            }

            if (cur == null)
            {
                return(null);
            }

            var cs = cur.GetPlane().GetCoordinateSystem();
            var o  = cs.Origin;
            var x  = cs.Xaxis;
            var y  = cs.Yaxis;

            var a  = reg.AreaProperties(ref o, ref x, ref y);
            var pl = new _AcGe.Plane(o, x, y);

            return(pl.EvaluatePoint(a.Centroid));
        }
Пример #2
0
        private _Ge.Point3d getCenter(_Db.Region reg)
        {
            _Db.Solid3d solid = new _Db.Solid3d();
            solid.Extrude(reg, 2.0, 0.0);
            _Ge.Point3d solidCentroid = solid.MassProperties.Centroid;

            return(new _Ge.Point3d(solidCentroid.X, solidCentroid.Y, 0));
        }
Пример #3
0
        // Region extensions

        ///<summary>
        /// Returns whether a Region contains a Point3d.
        ///</summary>
        ///<param name="pt">A points to test against the Region.</param>
        ///<returns>A Boolean indicating whether the Region contains
        /// the point.</returns>
        public static bool ContainsPoint(this _AcDb.Region reg, _AcGe.Point3d pt)
        {
            using (var brep = new _AcBr.Brep(reg))
            {
                var pc = new _AcBr.PointContainment();
                using (var brepEnt = brep.GetPointContainment(pt, out pc))
                {
                    return(pc != _AcBr.PointContainment.Outside);
                }
            }
        }
Пример #4
0
 ///<summary>
 /// Returns whether a Region contains a set of Point3ds.
 ///</summary>
 ///<param name="pts">An array of points to test against the Region.</param>
 ///<returns>A Boolean indicating whether the Region contains
 /// all the points.</returns>
 public static bool ContainsPoints(this _AcDb.Region reg, _AcGe.Point3d[] pts)
 {
     using (var brep = new _AcBr.Brep(reg))
     {
         foreach (var pt in pts)
         {
             var pc = new _AcBr.PointContainment();
             using (var brepEnt = brep.GetPointContainment(pt, out pc))
             {
                 if (pc == _AcBr.PointContainment.Outside)
                 {
                     return(false);
                 }
             }
         }
     }
     return(true);
 }
Пример #5
0
        public void run()
        {
            _Db.DBObjectCollection polys = getGeometry();
            if (polys.Count == 0)
            {
                throw new DMTException("Valida tuleb polyline tüüpi objekte");
            }

            try
            {
                _Db.Region  reg    = createRegion(polys);
                _Ge.Point3d center = getCenter(reg);

                string X = center.X.ToString("G").Replace(",", ".");
                string Y = center.Y.ToString("G").Replace(",", ".");

                write("Centroid: " + X + "," + Y);
                createBlock(center);
            }
            catch
            {
                throw new DMTException("Vigane geomeetria");
            }
        }
Пример #6
0
        private _Db.Region createRegion(_Db.DBObjectCollection polys)
        {
            _Db.DBObjectCollection regions = new _Db.DBObjectCollection();
            regions = _Db.Region.CreateFromCurves(polys);

            double area  = 0;
            int    index = 0;

            if (regions.Count > 1)
            {
                for (int i = 0; i < regions.Count; i++)
                {
                    _Db.Region cur = regions[i] as _Db.Region;
                    if (area < cur.Area)
                    {
                        index = i;
                        area  = cur.Area;
                    }
                }
            }


            _Db.Region bigRegion = regions[index] as _Db.Region;

            for (int i = 0; i < regions.Count; i++)
            {
                if (i == index)
                {
                    continue;
                }
                _Db.Region cur = regions[i] as _Db.Region;
                bigRegion.BooleanOperation(_Db.BooleanOperationType.BoolSubtract, cur);
            }

            return(bigRegion);
        }