明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索

[几何] 曲线处理专贴----我们的[原创]

    [复制链接]
 楼主| 发表于 2009-6-19 17:39 | 显示全部楼层

要多调试下:),椭圆的转换有点问题

效率暂时不考虑

 楼主| 发表于 2009-6-20 07:50 | 显示全部楼层
本帖最后由 作者 于 2009-6-23 21:11:20 编辑

发现问题在GetParamFromGeCurve方法
Ge的param和DB的param完全不是一回事
要把GeCurve打断再转换为DBCurve应该没问题
贴一个老外的DBCurve转GeCurve类,不完整:)
http://www.theswamp.org/index.php?topic=29217.0[url=http://www.cadtutor.net/forum/showthread.php?t=33523&page=3][/url]
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using Autodesk.AutoCAD.Runtime;
  5. using Autodesk.AutoCAD.DatabaseServices;
  6. using Autodesk.AutoCAD.Geometry;
  7. namespace GeometricConversion
  8. {
  9.     class EntityToGeom
  10.     {
  11.         //Fields
  12.         private CompositeCurve3d m_compCurve;
  13.         private Curve3d[] m_crvArray;
  14.         private Point3d[] m_points;
  15.         private int m_polyVCount;
  16.         private int m_distinctCurves;
  17.         private Boolean m_success;
  18.         private Boolean m_compositable;
  19.         private Curve m_curve;
  20.         private Tolerance m_tol;
  21.         private List<Curve3d> m_listCurve3d;
  22.         //Constructors
  23.         public EntityToGeom()
  24.         {
  25.             InitializeConstructor();
  26.         }
  27.         public EntityToGeom(Curve crv)
  28.         {
  29.             InitializeConstructor();
  30.             m_curve = crv;
  31.             ProcessCrv();
  32.         }
  33.         public EntityToGeom(Curve crv, Tolerance DesiredTolerance)
  34.         {
  35.             InitializeConstructor();
  36.             m_curve = crv;
  37.             m_tol = DesiredTolerance;
  38.         }
  39.         //Destructor
  40.         ~EntityToGeom()
  41.         {
  42.             m_curve.Dispose();
  43.         }
  44.         //Properties
  45.         public Boolean ConversionSuccess
  46.         {
  47.             get
  48.             {
  49.                 return m_success;
  50.             }
  51.         }
  52.         public int NumOfPolyVerts
  53.         {
  54.             get
  55.             {
  56.                 return m_polyVCount;
  57.             }
  58.         }
  59.         public CompositeCurve3d CurveGeometry
  60.         {
  61.             get
  62.             {
  63.                 return m_compCurve;
  64.             }
  65.         }
  66.         public Curve DatabaseCurve
  67.         {
  68.             set
  69.             {
  70.                 m_curve = value;
  71.                 ProcessCrv();
  72.             }
  73.         }
  74.         public Tolerance DesiredTolerance
  75.         {
  76.             set
  77.             {
  78.                 m_tol = DesiredTolerance;
  79.             }
  80.             get
  81.             {
  82.                 return m_tol;
  83.             }
  84.         }
  85.         //Internal
  86.         private void InitializeConstructor()
  87.         {
  88.             m_success = false;
  89.             m_compositable = true;
  90.             m_tol = new Tolerance();
  91.         }
  92.         private void ProcessCrv()
  93.         {
  94.             string crvTyp = m_curve.GetType().ToString();
  95.             switch (crvTyp)
  96.             {
  97.                 case "Autodesk.AutoCAD.DatabaseServices.Line":
  98.                     LineSegment3d ls3d = new LineSegment3d(m_curve.StartPoint, m_curve.EndPoint);
  99.                     m_crvArray = new Curve3d[1];
  100.                     m_crvArray[0] = ls3d;
  101.                     m_distinctCurves = 1;
  102.                     m_compositable = true;
  103.                     break;
  104.                 case "Autodesk.AutoCAD.DatabaseServices.Ray":
  105.                     ProcessConstruction(true);
  106.                     m_compositable = false;
  107.                     m_distinctCurves = 1;
  108.                     break;
  109.                 case "Autodesk.AutoCAD.DatabaseServices.XLine":
  110.                     ProcessConstruction(false);
  111.                     m_compositable = false;
  112.                     m_distinctCurves = 1;
  113.                     break;
  114.                 case "Autodesk.AutoCAD.DatabaseServices.Circle":
  115.                     ProcessCirculars(false);
  116.                     m_distinctCurves = 1;
  117.                     break;
  118.                 case "Autodesk.AutoCAD.DatabaseServices.Arc":
  119.                     ProcessCirculars(true);
  120.                     m_distinctCurves = 1;
  121.                     break;
  122.                 case "Autodesk.AutoCAD.DatabaseServices.Ellipse":
  123.                     ProcessEllipticals();
  124.                     m_distinctCurves = 1;
  125.                     break;
  126.                 case "Autodesk.AutoCAD.DatabaseServices.Polyline":
  127.                     ProcessPoly(true);
  128.                     break;
  129.                 case "Autodesk.AutoCAD.DatabaseServices.Polyline2d":
  130.                     ProcessPoly(false);
  131.                     break;
  132.                 case "Autodesk.AutoCAD.DatabaseServices.Polyline3d":
  133.                     ProcessPoly3d();
  134.                     break;
  135.                 case "Autodesk.AutoCAD.DatabaseServices.Spline":
  136.                     ProcessSpline();
  137.                     m_distinctCurves = 1;
  138.                     break;
  139.             }
  140.             if (m_compositable)
  141.             {
  142.                 try
  143.                 {
  144.                     m_compCurve = new CompositeCurve3d(m_crvArray);
  145.                     m_success = true;
  146.                 }
  147.                 catch
  148.                 {
  149.                     m_success = false;
  150.                 }
  151.             }
  152.             else
  153.             {
  154.                 m_success = false;
  155.             }
  156.         }
  157.         private void ProcessPoly(Boolean LightWeight)
  158.         {
  159.             Polyline2d p2d;
  160.             if (LightWeight)
  161.             {
  162.                 Polyline p = m_curve as Polyline;
  163.                 p2d = p.ConvertTo(false);
  164.                 p.Dispose();
  165.             }
  166.             else
  167.             {
  168.                 p2d = m_curve as Polyline2d;
  169.             }
  170.             switch (p2d.PolyType)
  171.             {
  172.                 case Poly2dType.SimplePoly:
  173.                     ProcessSimplePolys(p2d);
  174.                     break;
  175.                 case Poly2dType.FitCurvePoly:
  176.                     ProcessFitPoly(p2d);
  177.                     break;
  178.                 case Poly2dType.QuadSplinePoly:
  179.                     ProcessSplinePoly2d(p2d, 2);
  180.                     break;
  181.                 case Poly2dType.CubicSplinePoly:
  182.                     ProcessSplinePoly2d(p2d, 3);
  183.                     break;
  184.             }
  185.             ProcessCurveList();
  186.         }
  187.         private void ProcessPoly3d()
  188.         {
  189.             Polyline3d p3d = m_curve as Polyline3d;
  190.             Database db = HostApplicationServices.WorkingDatabase;
  191.             using (Transaction trans = db.TransactionManager.StartTransaction())
  192.             {
  193.                 PolylineVertex3d pv3d;
  194.                 m_polyVCount = Convert.ToInt32(p3d.EndParam);
  195.                 m_points = new Point3d[m_polyVCount + 1];
  196.                 int i = 0;
  197.                 foreach (ObjectId oid in p3d)
  198.                 {
  199.                     pv3d = trans.GetObject(oid, OpenMode.ForRead) as PolylineVertex3d;
  200.                     m_points[i] = pv3d.Position;
  201.                     if (i > 0)
  202.                     {
  203.                         if (!m_points[i].IsEqualTo(m_points[i - 1], m_tol))
  204.                         {                        
  205.                             switch (p3d.PolyType)
  206.                             {
  207.                                 case Poly3dType.SimplePoly:
  208.                                     m_listCurve3d.Add(new LineSegment3d(m_points[i - 1], m_points[i]));
  209.                                     m_distinctCurves = m_listCurve3d.Count;
  210.                                     break;
  211.                                 case Poly3dType.QuadSplinePoly:
  212.                                     ProcessSplinePoly3d(p3d, 2);
  213.                                     m_distinctCurves = 1;
  214.                                     break;
  215.                                 case Poly3dType.CubicSplinePoly:
  216.                                     ProcessSplinePoly3d(p3d, 3);
  217.                                     m_distinctCurves = 1;
  218.                                     break;
  219.                             }
  220.                         }
  221.                     }
  222.                     i++;
  223.                 }
  224.                 p3d.Dispose();
  225.             }
  226.             ProcessCurveList();
  227.         }
  228.         private void ProcessSpline()
  229.         {
  230.             Spline spl = m_curve as Spline;
  231.             NurbCurve3d nc3d;
  232.             if (spl.HasFitData)
  233.             {
  234.                 Vector3dCollection v3c;
  235.                 FitData fd = spl.FitData;
  236.                 if (fd.TangentsExist)
  237.                 {
  238.                     v3c = TangentVectorContainer(fd);
  239.                     nc3d = new NurbCurve3d(fd.GetFitPoints(), v3c, spl.IsPeriodic);
  240.                 }
  241.                 else
  242.                 {
  243.                     nc3d = new NurbCurve3d(fd.GetFitPoints(), new Vector3d(), new Vector3d(), false, false);   
  244.                 }
  245.             }
  246.             else
  247.             {
  248.                 NurbsData nd = spl.NurbsData;
  249.                 DoubleCollection dc = nd.GetKnots();
  250.                 KnotCollection kc = new KnotCollection();
  251.                 foreach (Double d in dc)
  252.                 {
  253.                     kc.Add(d);
  254.                 }
  255.                 Point3dCollection p3cCP = nd.GetControlPoints();
  256.                 if (nd.Rational)
  257.                 {
  258.                     DoubleCollection dcw = nd.GetWeights();
  259.                     nc3d = new NurbCurve3d(nd.Degree, kc, p3cCP, dcw, nd.Periodic);
  260.                 }
  261.                 else
  262.                 {
  263.                     nc3d = new NurbCurve3d(nd.Degree, kc, p3cCP, nd.Periodic);
  264.                 }
  265.             }
  266.             m_crvArray = new Curve3d[1];
  267.             m_crvArray[0] = nc3d;
  268.             spl.Dispose();
  269.         }
  270.         private void ProcessConstruction(Boolean StartPoint)
  271.         {
  272.             if (StartPoint)
  273.             {
  274.                 Ray r = m_curve as Ray;
  275.                 Ray3d r3d = new Ray3d(r.BasePoint, r.SecondPoint);
  276.                 m_crvArray = new Curve3d[1];
  277.                 m_crvArray[0] = r3d;
  278.                 r.Dispose();
  279.             }
  280.             else
  281.             {
  282.                 Xline x = m_curve as Xline;
  283.                 Line3d l3d = new Line3d(x.BasePoint, x.SecondPoint);
  284.                 m_crvArray = new Curve3d[1];
  285.                 m_crvArray[0] = l3d;
  286.                 x.Dispose();
  287.             }
  288.         }
  289.         private void ProcessCirculars(Boolean isArc)
  290.         {
  291.             if (isArc)
  292.             {
  293.                 Arc a = m_curve as Arc;
  294.                 Double param = (a.StartParam + a.EndParam) / 2;
  295.                 Point3d p3d = a.GetPointAtParameter(param);
  296.                 CircularArc3d ca3 = new CircularArc3d(a.StartPoint, p3d, a.EndPoint);
  297.                 m_crvArray = new Curve3d[1];
  298.                 m_crvArray[0] = ca3;
  299.                 a.Dispose();
  300.             }
  301.             else
  302.             {
  303.                 Circle c = m_curve as Circle;
  304.                 CircularArc3d ca3 = new CircularArc3d(c.Center, c.Normal, c.Radius);
  305.                 m_crvArray = new Curve3d[1];
  306.                 m_crvArray[0] = ca3;
  307.                 c.Dispose();
  308.             }
  309.         }
  310.         private void ProcessEllipticals()
  311.         {
  312.             Ellipse e = m_curve as Ellipse;
  313.             EllipticalArc3d ea3 = new EllipticalArc3d(e.Center, e.MajorAxis, e.MinorAxis,
  314.                 e.MajorRadius, e.MinorRadius, e.StartParam, e.EndParam);
  315.             m_crvArray = new Curve3d[1];
  316.             m_crvArray[0] = ea3;
  317.             e.Dispose();
  318.         }
  319.         private Vector3dCollection TangentVectorContainer(FitData fd)
  320.         {
  321.             Vector3dCollection v3c = new Vector3dCollection(2);
  322.             v3c.Add(fd.StartTangent);
  323.             v3c.Add(fd.EndTangent);
  324.             return v3c;
  325.         }
  326.         private void ProcessCurveList()
  327.         {
  328.             m_listCurve3d.TrimExcess();
  329.             int i = m_listCurve3d.Count;
  330.             m_crvArray = new Curve3d[i];
  331.             for (int j = 0; j < i; j++)
  332.             {
  333.                 m_crvArray[j] = m_listCurve3d[j];
  334.             }
  335.             
  336.         }
  337.         private void ProcessSimplePolys(Polyline2d p2d)
  338.         {
  339.             Database db = HostApplicationServices.WorkingDatabase;
  340.             using (Transaction trans = db.TransactionManager.StartTransaction())
  341.             {
  342.                 m_polyVCount = Convert.ToInt32(p2d.EndParam);
  343.                 m_points = new Point3d[m_polyVCount + 1];
  344.                 m_listCurve3d = new List<Curve3d>();
  345.                 int i = 0;
  346.                 Double bulge = 0.0;
  347.                 Double param = 0.0;
  348.                 foreach (Vertex2d v2d in p2d)
  349.                 {
  350.                     m_points[i] = p2d.VertexPosition(v2d);
  351.                     if (i > 0)
  352.                     {
  353.                         if (!m_points[i].IsEqualTo(m_points[i - 1], m_tol))
  354.                         {
  355.                             bulge = Math.Round(bulge, 6);
  356.                             if (bulge != 0.0)
  357.                             {
  358.                                 param = Convert.ToDouble(i) - 0.5;
  359.                                 Point3d pt3 = p2d.GetPointAtParameter(param);
  360.                                 m_listCurve3d.Add(new CircularArc3d(m_points[i - 1], pt3, m_points[i]));
  361.                             }
  362.                             else
  363.                             {
  364.                                 m_listCurve3d.Add(new LineSegment3d(m_points[i - 1], m_points[i]));
  365.                             }
  366.                         }
  367.                     }
  368.                     i++;
  369.                     bulge = v2d.Bulge;
  370.                 }
  371.                 p2d.Dispose();
  372.             }
  373.         }
  374.         private void ProcessFitPoly(Polyline2d p2d)
  375.         {
  376.             int i = 0;
  377.             Double param;
  378.             foreach (Vertex2d v2d in p2d)
  379.             {
  380.                 m_points[i] = p2d.VertexPosition(v2d);
  381.                 if (i > 0)
  382.                 {
  383.                     if (!m_points[i].IsEqualTo(m_points[i - 1], m_tol))
  384.                     {
  385.                         param = Convert.ToDouble(i) - 0.5;
  386.                         Point3d pt3 = p2d.GetPointAtParameter(param);
  387.                         m_listCurve3d.Add(new CircularArc3d(m_points[i - 1], pt3, m_points[i]));
  388.                     }
  389.                 }
  390.                 i++;
  391.             }
  392.         }
  393.         private void ProcessSplinePoly2d(Polyline2d p3d, int degree)
  394.         {
  395.         }
  396.         private void ProcessSplinePoly3d(Polyline3d p3d, int degree)
  397.         {
  398.         }
  399.     }
  400. }
 楼主| 发表于 2009-6-20 16:02 | 显示全部楼层

曲线打断第二版已修正

发表于 2009-8-24 14:57 | 显示全部楼层

俺综合一下各位的帖子,整理了一下

  1.         public static void TRimByPolyline()
  2.         {
  3.             Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
  4.             Database db = doc.Database;
  5.             Editor ed = doc.Editor;
  6.             Polyline cutBox;
  7.             //选择曲线
  8.             PromptEntityResult per = ed.GetEntity("选择边线");
  9.             if (per.Status != PromptStatus.OK) return;
  10.             using (Transaction tr = db.TransactionManager.StartTransaction())
  11.             {
  12.                 DBObject pDBObj= tr.GetObject(per.ObjectId, Autodesk.AutoCAD.DatabaseServices.OpenMode.ForRead);//剪切边界实体
  13.                 if (pDBObj.GetType().Name.ToString() != "Polyline")
  14.                 {
  15.                     MessageBox.Show("选择的不是Polyline线");
  16.                     return;
  17.                 }
  18.                 cutBox = (Polyline)pDBObj;
  19.                 Point3dCollection cutBoxPC = new Point3dCollection();
  20.                 for (int i = 0; i < cutBox.NumberOfVertices; i++)
  21.                     cutBoxPC.Add(cutBox.GetPoint3dAt(i));
  22.                 PromptSelectionResult res = ed.SelectFence(cutBoxPC, new SelectionFilter(new TypedValue[] { new TypedValue(0, "*Line,Arc,Circle,Ellipse") }));// GetSelection(new PromptSelectionOptions(), new SelectionFilter(new TypedValue[] { new TypedValue(0, "*Line,Arc,Circle,Ellipse") }));
  23.                 ObjectId[] ids = res.Value.GetObjectIds();
  24.                 ObjectIdCollection oldids = new ObjectIdCollection();
  25.                 BlockTableRecord btr =
  26.                     (BlockTableRecord)tr.GetObject(
  27.                         db.CurrentSpaceId,
  28.                         Autodesk.AutoCAD.DatabaseServices.OpenMode.ForWrite,
  29.                         false);
  30.                 //遍历选择集
  31.                 foreach (ObjectId i in ids)
  32.                 {
  33.                     List<double> pars = new List<double>();
  34.                     Curve iCurve = (Curve)tr.GetObject(i, Autodesk.AutoCAD.DatabaseServices.OpenMode.ForRead);
  35.                     Point3dCollection iwpnts = new Point3dCollection();
  36.                     iCurve.IntersectWith(cutBox, Intersect.OnBothOperands, iwpnts, 0, 0);
  37.                     foreach (Point3d p in iwpnts)
  38.                     {
  39.                         pars.Add(iCurve.GetParameterAtPoint(p));
  40.                     }
  41.                     //如果有交点,按param值排序并打断
  42.                     if (pars.Count > 0)
  43.                     {
  44.                         pars.Sort();
  45.                         try
  46.                         {
  47.                             //将子曲线加入数据库,原曲线加入oldids集合
  48.                             foreach (Curve c in iCurve.GetSplitCurves(new DoubleCollection(pars.ToArray())))
  49.                             {
  50.                                 btr.AppendEntity(c);
  51.                                 tr.AddNewlyCreatedDBObject(c, true);
  52.                             }
  53.                             oldids.Add(i);
  54.                         }
  55.                         catch
  56.                         { }
  57.                     }
  58.                 }
  59.                 foreach (ObjectId id in oldids)
  60.                 {
  61.                     tr.GetObject(id, Autodesk.AutoCAD.DatabaseServices.OpenMode.ForWrite).Erase();
  62.                 }
  63.                 tr.Commit();
  64.             }
  65.         }
可是在附件里运行出现各种错误,还希望各位指点
 楼主| 发表于 2009-8-24 15:20 | 显示全部楼层
裁剪的话,以前给网友改过类似的
下面一段是打断的例程,当然,后续的判断部分要自己加
  1. &#160; &#160;&#160; &#160;&#160;&#160;[CommandMethod("tttt")]
  2. &#160; &#160;&#160; &#160;&#160;&#160;public static void plqt()//批量裁剪图幅
  3. &#160; &#160;&#160; &#160;&#160;&#160;{
  4. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;TypedValue[] txtvalue = { new TypedValue((int)DxfCode.Start, "LWPOLYLINE")};
  5. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;SelectionFilter flter = new SelectionFilter(txtvalue);
  6. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;PromptSelectionResult myset = TlsTM.Editor.GetSelection(flter);
  7. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;if (myset.Status == PromptStatus.OK)
  8. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;{
  9. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; #region//搜索边界
  10. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; using (TlsETM tm = new TlsETM())
  11. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; {
  12. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160;&#160;tm.OpenCurrentSpace();
  13. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160;&#160;foreach (ObjectId id in myset.Value.GetObjectIds())
  14. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160;&#160;{
  15. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;Entity myent = (Entity)tm.GetObject(id, OpenMode.ForRead);
  16. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;if (myent.GetType().Name == "olyline")
  17. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;{
  18. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; #region//取得打断边界实体
  19. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; Curve iCurve = (Curve)myent;
  20. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; #endregion
  21. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; #region//开始打断实体
  22. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; TypedValue[] ent = { new TypedValue(0, "*Line,Arc,Circle,Ellipse") };
  23. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; SelectionFilter terf = new SelectionFilter(ent);
  24. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; PromptSelectionResult entRes = TlsTM.Editor.SelectAll(terf);
  25. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; DBObjectCollection myobjCol = new DBObjectCollection();
  26. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; foreach (ObjectId myid in entRes.Value.GetObjectIds())
  27. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; {
  28. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160;&#160;List<oint3d> pnts = new List<oint3d>();
  29. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160;&#160;List<double> dists = new List<double>();
  30. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160;&#160;if (id != myid)
  31. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160;&#160;{
  32. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;Curve jCurve = (Curve)tm.GetObject(myid, OpenMode.ForWrite);
  33. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;Point3dCollection ptcol = new Point3dCollection();
  34. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;jCurve.IntersectWith(iCurve, Intersect.OnBothOperands, ptcol, 0, 0);
  35. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;foreach (Point3d p in ptcol)
  36. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;{
  37. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; pnts.Add(p);
  38. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; dists.Add(jCurve.GetDistAtPoint(p));
  39. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;}//endforeach
  40. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;if (pnts.Count > 0)
  41. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;{
  42. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; Point3d[] pntarr = pnts.ToArray();
  43. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; Array.Sort(dists.ToArray(), pntarr);
  44. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; try
  45. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; {
  46. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160;&#160;myobjCol = jCurve.GetSplitCurves(new Point3dCollection(pntarr));
  47. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160;&#160;foreach (DBObject obj in myobjCol)
  48. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160;&#160;{
  49. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;Entity ee = (Entity)obj;
  50. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;tm.AddEntity(ee);
  51. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160;&#160;}
  52. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; }
  53. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; catch
  54. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; {
  55. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; }
  56. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;}
  57. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160;&#160;}
  58. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; #endregion
  59. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; }//end foreach
  60. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;}//end if
  61. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160;&#160;}//end foreach
  62. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; }//endusing
  63. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; #endregion//搜索边界
  64. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;}
  65. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;else
  66. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; return;//end if
  67. &#160; &#160;&#160; &#160;&#160;&#160;}//end void
发表于 2009-8-24 16:41 | 显示全部楼层

一样的错误{"eInvalidInput"}

在这句dists.Add(jCurve.GetDistAtPoint(p));

pars.Add(iCurve.GetParameterAtPoint(p));

 楼主| 发表于 2009-8-24 17:12 | 显示全部楼层
用GetClosestPointTo函数获取曲线上的最近点,DB曲线有这样的Bug
发表于 2009-8-25 14:04 | 显示全部楼层
作为打断点?
 楼主| 发表于 2009-8-25 14:11 | 显示全部楼层

DB曲线的GetXXX函数是有误差的,有时会出现获取的点不在曲线上,用GetClosestPointTo消除
但在曲线很短的时候会出现获取的点缺失
建议把DB曲线转换为Ge曲线操作,上面的帖子以及我的TlsBasal类和曲线转换类有相关的例程,你可以看下

发表于 2009-8-26 10:13 | 显示全部楼层

谢谢楼主提供材料!

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-3-29 15:37 , Processed in 0.252493 second(s), 17 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表