求两条直线交点时可以使用IntersectWith方法,但对于我这种初学者有点摸不清该怎么使用。
直接上代码吧
[CommandMethod("GTest")]public static void GTest(){var p1 = new Point3d(0, 0, 0);var p2 = new Point3d(100, 0, 0);var p3 = new Point3d(100, 100, 0);var p4 = new Point3d(0, 100, 0);var line = new Line(p1, p2);//创建直线var s1 = new Point3d(80, -40, 0);var s2 = new Point3d(20, 90, 0);var line2 = new Line(s1, s2);Point3dCollection pt3Coll = new Point3dCollection();//交点集合line2.IntersectWith(line, Intersect.ExtendBoth, pt3Coll, IntPtr.Zero, IntPtr.Zero);if (pt3Coll.Count > 0)//交点集合 2个交点{foreach (var jd in pt3Coll){var t = jd;}}pt3Coll = new Point3dCollection();//交点集合var circle = new Circle(new Point3d(50, 10, 0), new Vector3d(0, 0, 1), 50);//创建r=50的圆 circle.IntersectWith(line, Intersect.OnBothOperands, pt3Coll, IntPtr.Zero, IntPtr.Zero);if (pt3Coll.Count > 0)//交点集合 2个交点{foreach (var jd in pt3Coll){var t = jd;}}pt3Coll = new Point3dCollection();//交点集合var arc = new Arc(new Point3d(50, 10, 0), new Vector3d(0, 0, 1), 50, 0, 1.5 * Math.PI);//创建r=50,3/4的圆弧, arc.IntersectWith(line, Intersect.OnBothOperands, pt3Coll, IntPtr.Zero, IntPtr.Zero);if (pt3Coll.Count > 0)//交点集合 1个交点{foreach (var jd in pt3Coll){var t = jd;}}}
以上代码摘自AutoCAD 二次开发 求线的交点 - 点击领取 ()
------------------------------------------------
关于其中的参数,解释如下
Entity entityPointer:与该实体相交的另一个实体
Intersect intersectType:相交的类型,为一枚举,见下表
Point3dCollection points:获取所有相交的交点
Int32 thisGraphicSystemMarker:使用该方法实体的下级实体(subentity)的图形系统标记,如果不适用就用缺省值0。
Int32 otherGraphicSystemMarker:其他的下级实体的图形系统标记,如果不适用就用缺省值0。
关于Intersect枚举的成员
摘自(16条消息) AutoCAD的IntersectWith方法_weixin_30492601的博客-CSDN博客
------------------------------------------
内容大部分来源于网络,做了一点整理,方便后期查看,如果文章侵犯了您的权益,请联系我删除