Esempio n. 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));
        }
Esempio n. 2
0
        private List <_Ge.Point3d> handle(_Db.Entity ent)
        {
            List <_Ge.Point3d> points = new List <_Ge.Point3d>();

            if (ent == null)
            {
                return(points);
            }


            if (ent is _Db.Curve && !(ent is _Db.Polyline || ent is _Db.Polyline2d || ent is _Db.Polyline3d))
            {
                try
                {
                    _Db.Curve cur = ent as _Db.Curve;

                    int segs = 3; //(ent is Line ? 3 : 20);

                    double param = cur.EndParam - cur.StartParam;

                    for (int i = 0; i < segs; i++)
                    {
                        try
                        {
                            _Ge.Point3d pt = cur.GetPointAtParameter(cur.StartParam + (i * param / (segs - 1)));
                            points.Add(pt);
                        }
                        catch { }
                    }
                }
                catch { }
            }
            else
            {
                _Db.DBObjectCollection objectCollection = new _Db.DBObjectCollection();
                try
                {
                    ent.Explode(objectCollection);
                    if (objectCollection.Count > 0)
                    {
                        foreach (_Db.DBObject bid in objectCollection)
                        {
                            _Db.Entity ent2 = bid as _Db.Entity;
                            if (ent2 != null && ent2.Visible)
                            {
                                List <_Ge.Point3d> currentPoints = handle(ent2);
                                points.AddRange(currentPoints);
                            }
                            bid.Dispose();
                        }
                    }
                }
                catch { }
            }

            if (ent is _Db.Circle)
            {
                _Db.Circle         circle       = ent as _Db.Circle;
                List <_Ge.Point3d> circlePoints = getCirclePoints(circle);
                points.AddRange(circlePoints);
            }
            else if (ent is _Db.Arc)
            {
                _Db.Arc            arc       = ent as _Db.Arc;
                List <_Ge.Point3d> arcPoints = getArcPoints(arc);
                points.AddRange(arcPoints);
            }

            return(points);
        }
Esempio n. 3
0
 static private Curve ToRhino(this _OdDb.Curve crv)
 {
     return(crv.GetGeCurve().ToRhino());
 }