小狼 发表于 2009-12-9 15:39:00

获取 Curve 坐标方法


///
      /// 获取线对象上的坐标集和突度集
      ///
      /// Curve对象
      /// 坐标集
      /// 突度集
      public static void GetPolylinePoint3dsAndBulge(this Curve curve,ref Point3dCollection Point3dColl,ref DoubleCollection Bulges)
      {
            try
            {
               
                Point3dColl.Clear();
                Bulges.Clear();
                switch (curve.GetEntityType())
                {
                  case "Polyline":
                        Polyline polylineObject = (Polyline)curve;
                        int NumberOfVertices = polylineObject.NumberOfVertices;
                        for (int i = 0; i
      /// 返回CAD对象类型
      ///
      /// 对象名称
      ///
      public static string GetEntityType(this Entity ent)
      {
            try
            {
                return ent.GetType().ToString().Replace("Autodesk..DatabaseServices.", "");
            }
            catch
            {
                return "";
            }
      } ///
      /// 获取ObjectId的Entity
      ///
      /// 对象ID
      /// 事务处理对象
      /// 读取模式
      ///
      public static DBObject GetEntity(this ObjectId ObjId, Transaction trans, OpenMode openmode, bool openErased, bool forceOpenOnLockeDLayer)
      {
            try
            {
                return (DBObject)trans.GetObject(ObjId, openmode, openErased, forceOpenOnLockeDLayer);
            }
            catch (Exception)
            {
                return null;
            }
      }
///后面部分是抄的,原来自己写的方向有时候有问题
///忘记哪里了,急用没留地址,找不到了
///希望这位朋友不要介意啊,哈哈
      //计算凸起值
      public static double GetBulge(this Arc A, bool SEbo)
      {
            double Bulge = 0;
            double L1 = GetDistance(A.StartPoint, A.EndPoint);
            double Angle = A.EndAngle - A.StartAngle;
            if (AngleMath.PI)
            {
                //判断是否大于180度
                Bulge = A.Radius + Math.Sqrt(Math.Pow(A.Radius, 2) - Math.Pow((L1 / 2), 2));
                //计算凸起值
            }
            else
            {
                Bulge = A.Radius - Math.Sqrt(Math.Pow(A.Radius, 2) - Math.Pow((L1 / 2), 2));
                //计算凸起值
            }
            Point3d Pt2 = A.GetPointAtDist(A.GetDistanceAtParameter(A.EndParam) / 2);
            //取中点
            double TempDouble = 0;
            if (SEbo == true)
            {
                //判断方向
                TempDouble = PtSide(A.StartPoint, Pt2, A.EndPoint);
            }
            else
            {
                TempDouble = PtSide(A.EndPoint, Pt2, A.StartPoint);
            }
            if (TempDouble > 0)
            {
                //判断圆弧是凸向哪边
                return -Bulge / (L1 / 2);
            }
            else
            {
                return Bulge / (L1 / 2);
            }
      }
      //判断圆弧是凸向哪边
      private static double PtSide(Point3d pt1, Point3d pt2, Point3d pt3)
      {
            Vector3d vect1 = pt1.GetVectorTo(pt2);
            Vector3d vect2 = pt1.GetVectorTo(pt3);
            return vect2.X * vect1.Y - vect1.X * vect2.Y;
      }
扩展方法需要放在静态类里面

lzx838 发表于 2009-12-9 17:34:00

小狼兄发贴啦
大家快来支持啊

liminnet 发表于 2009-12-10 17:33:00

好东西,支持下,收藏啦

游天居士 发表于 2009-12-13 22:06:00

收藏一下先。以后有用的时候来再来

游天居士 发表于 2009-12-17 21:48:00

谢谢。
我这几一正在看ployline
再次谢谢!!

gruand 发表于 2013-8-5 16:00:00

终于找到了。支持下
页: [1]
查看完整版本: 获取 Curve 坐标方法