CAD二次开发之IntersectWith

IntersectWith用来寻找两个实体的交点

public unsafe void IntersectWith(
  Entity entityPointer,
  Intersect intersectType,
  Point3dCollection points,
  IntPtr thisGraphicSystemMarker,
  IntPtr otherGraphicSystemMarker)

此函数应用于两个Entity的简单相交,返回值为Entity的的点集

  • entityPointer:相交的另一个Entity

  • intersectType:计算交点的方式

    namespace Autodesk.AutoCAD.DatabaseServices {
      [Wrapper("AcDb::Intersect")]
      public enum Intersect  {
        OnBothOperands,
        ExtendThis,
        ExtendArgument,
        ExtendBoth,
      }
    }
    
    • Intersect.OnBothOperands :实际交点
    • Intersect.ExtendThis : 延长IntersectWith之前的Entity
    • Intersect.ExtendArgument : 延长entityPointer
    • Intersect.ExtendBoth : 两个都延长
  • points : 点集

  • thisGraphicSystemMarker :下级实体的图形系统标记,如果不适用就用缺省值IntPtr.Zero

  • otherGraphicSystemMarker :下级实体的图形系统标记,如果不适用就用缺省值IntPtr.Zero

示例程序

public static void IntersectWithTest () {

    Database db = HostApplicationServices.WorkingDatabase;
    Editor editor = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
  
    Line line1 = new Line();
    line1.StartPoint = new Point3d(0, 0, 0);
    line1.EndPoint = new Point3d(0, 100, 0);
   
    Circle circle = new Circle();
    circle.Center = new Point3d(0, 0, 0);
    circle.Radius = 80;

    //放交点的集合
    Point3dCollection intersectionPoints1 = new Point3dCollection();
    line1.IntersectWith(circle, Intersect.OnBothOperands, intersectionPoints1, IntPtr.Zero,IntPtr.Zero);
    //intersectionPoints1 中有一个点 (0, 80, 0)
    Point3dCollection intersectionPoints2 = new Point3dCollection();
    circle.IntersectWith(line1, Intersect.OnBothOperands, intersectionPoints2, IntPtr.Zero, IntPtr.Zero);
    //intersectionPoints2 中有一个点 (0, 80, 0)

    Point3dCollection intersectionPoints3 = new Point3dCollection();
    line1.IntersectWith(circle, Intersect.ExtendThis, intersectionPoints3, IntPtr.Zero,IntPtr.Zero);
    //intersectionPoints3 中有两个点 (0, 80, 0)(0, -80, 0)
    Point3dCollection intersectionPoints4 = new Point3dCollection();
    circle.IntersectWith(line1, Intersect.ExtendThis, intersectionPoints4, IntPtr.Zero, IntPtr.Zero);
    //intersectionPoints4 中有一个点 (0, 80, 0)

    Point3dCollection intersectionPoints5 = new Point3dCollection();
    line1.IntersectWith(circle, Intersect.ExtendArgument, intersectionPoints5, IntPtr.Zero, IntPtr.Zero);
    //intersectionPoints5 中有一个点 (0, 80, 0)
    Point3dCollection intersectionPoints6 = new Point3dCollection();
    circle.IntersectWith(line1, Intersect.ExtendArgument, intersectionPoints6, IntPtr.Zero, IntPtr.Zero);
    //intersectionPoints6 中有两个点 (0, 80, 0)(0, -80, 0)

    Point3dCollection intersectionPoints7 = new Point3dCollection();
    line1.IntersectWith(circle, Intersect.ExtendBoth, intersectionPoints7, IntPtr.Zero, IntPtr.Zero);
    //intersectionPoints7 中有两个点 (0, 80, 0)(0, -80, 0)
    Point3dCollection intersectionPoints8 = new Point3dCollection();
    circle.IntersectWith(line1, Intersect.ExtendBoth, intersectionPoints8, IntPtr.Zero, IntPtr.Zero);
    //intersectionPoints8 中有两个点 (0, 80, 0)(0, -80, 0)

}
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容