明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 10539|回复: 11

如何获取两条直线的交点?

[复制链接]
发表于 2011-3-24 22:05 | 显示全部楼层 |阅读模式
  如何获取两条直线的交点?有什么函数吗?还有,对多段线进行内部填充时多段线必须是封闭的吗?
发表于 2011-3-24 23:29 | 显示全部楼层
public virtual void IntersectWith(Autodesk.AutoCAD.DatabaseServices.Entity entityPointer, Autodesk.AutoCAD.DatabaseServices.Intersect intersectType, Autodesk.AutoCAD.Geometry.Point3dCollection points, int thisGraphicSystemMarker, int otherGraphicSystemMarker)
    Autodesk.AutoCAD.DatabaseServices.Entity 的成员
public virtual void IntersectWith(Autodesk.AutoCAD.DatabaseServices.Entity entityPointer, Autodesk.AutoCAD.DatabaseServices.Intersect intersectType, Autodesk.AutoCAD.Geometry.Plane projectionPlane, Autodesk.AutoCAD.Geometry.Point3dCollection points, int thisGraphicSystemMarker, int otherGraphicSystemMarker)
    Autodesk.AutoCAD.DatabaseServices.Entity 的成员
发表于 2011-3-24 23:31 | 显示全部楼层
是要求曲线组成一个封闭区域,若是一个多义线则要求多义线是封闭的,也可以多个不封闭的多义线相连成一个封闭轮廓。
 楼主| 发表于 2011-3-29 09:56 | 显示全部楼层
回复 sieben 的帖子

这两个函数好难看懂啊!那我也可以写一个方法来求线段的交点吧?
发表于 2011-3-29 10:33 | 显示全部楼层
发表于 2011-3-29 12:01 | 显示全部楼层
家在湾里 发表于 2011-3-29 09:56
回复 sieben 的帖子

这两个函数好难看懂啊!那我也可以写一个方法来求线段的交点吧?

呵呵,当然,所有的函数都是人写出来的,别人可以,当然你也可以!
下面是个示意,希望能帮到你。
    /// <summary>
    /// 求两条曲线的交点,本函数为应对Polyline.IntersectWith函数的Bug
    /// Vrsion : 2009.02.10 Sieben
    /// Vrsion : 2010.12.25 增加判断输入实体是否为平面实体
    /// </summary>
    /// <param name="ent1"></param>
    /// <param name="ent2"></param>
    /// <returns></returns>
    public static Point3dCollection IntersectWith(Entity ent1, Entity ent2, Intersect intersectType)
    {
      try
      {
        if (ent1 is Polyline || ent2 is Polyline)
        {
          if (ent1 is Polyline && ent2 is Polyline)
          {
            Polyline pline1 = (Polyline)ent1;
            Polyline pline2 = (Polyline)ent2;
            return IntersectWith(pline1.ConvertTo(false), pline2.ConvertTo(false), intersectType);
          }
          else if (ent1 is Polyline)
          {
            Polyline pline1 = (Polyline)ent1;
            return IntersectWith(pline1.ConvertTo(false), ent2, intersectType);
          }
          else
          {
            Polyline pline2 = (Polyline)ent2;
            return IntersectWith(ent1, pline2.ConvertTo(false), intersectType);
          }
        }
        else
        {
          Point3dCollection interPs = new Point3dCollection();
          if (ent1.IsPlanar && ent2.IsPlanar)
            ent1.IntersectWith(ent2, intersectType, new Plane(Point3d.Origin, Vector3d.ZAxis), interPs, 0, 0);
          else
            ent1.IntersectWith(ent2, intersectType, interPs, 0, 0);
          return interPs;
        }
      }
      catch (System.Exception ex)
      {
        return null;
      }
    }
发表于 2011-3-29 12:08 | 显示全部楼层
    /// <summary>
    /// 求两两连线的交点
    /// </summary>
    /// <param name="P11">第一组点</param>
    /// <param name="P12">第一组点</param>
    /// <param name="P21">第二组点</param>
    /// <param name="P22">第二组点</param>
    /// <returns>若有交点就返回交点,否则返回P11</returns>
    static public Point3d PLL(Point3d P11, Point3d P12, Point3d P21, Point3d P22)
    {
      double A1 = P12.Y - P11.Y;
      double B1 = P11.X - P12.X;
      double C1 = -A1 * P11.X - B1 * P11.Y;
      double A2 = P22.Y - P21.Y;
      double B2 = P21.X - P22.X;
      double C2 = -A2 * P21.X - B2 * P21.Y;
      double dlt = A1 * B2 - A2 * B1;
      double dltx = C1 * B2 - C2 * B1;
      double dlty = A1 * C2 - A2 * C1;
      if (Math.Abs(dlt) < 0.00000001)
      {
        return P11;
      }
      else
      {
        return new Point3d(-1.0 * (dltx / dlt), -1.0 * (dlty / dlt), 0);
      }
    }
注意,直线的交点和直线段的交点是有区别的
 楼主| 发表于 2011-3-31 16:29 | 显示全部楼层
回复 cdinten 的帖子

你是武大的?呵呵
 楼主| 发表于 2011-3-31 16:30 | 显示全部楼层
回复 sieben 的帖子

谢谢sieben,对我来说很有用。
发表于 2013-10-29 11:47 | 显示全部楼层
非常感谢!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-5-6 20:38 , Processed in 0.230691 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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