乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 121|回复: 9

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

[复制链接]

6

主题

30

帖子

4

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
54
发表于 2011-3-24 22:05:00 | 显示全部楼层 |阅读模式
如何获取两条直线的交点?有什么函数吗?还有,对多段线进行内部填充时多段线必须是封闭的吗?
回复

使用道具 举报

32

主题

651

帖子

8

银币

中流砥柱

Rank: 25

铜币
779
发表于 2011-3-24 23:29:00 | 显示全部楼层
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 的成员
回复

使用道具 举报

32

主题

651

帖子

8

银币

中流砥柱

Rank: 25

铜币
779
发表于 2011-3-24 23:31:00 | 显示全部楼层
是要求曲线组成一个封闭区域,若是一个多义线则要求多义线是封闭的,也可以多个不封闭的多义线相连成一个封闭轮廓。
回复

使用道具 举报

6

主题

30

帖子

4

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
54
发表于 2011-3-29 09:56:00 | 显示全部楼层
回复
这两个函数好难看懂啊!那我也可以写一个方法来求线段的交点吧?
回复

使用道具 举报

19

主题

154

帖子

5

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
230
发表于 2011-3-29 10:33:00 | 显示全部楼层
回复

使用道具 举报

32

主题

651

帖子

8

银币

中流砥柱

Rank: 25

铜币
779
发表于 2011-3-29 12:01:00 | 显示全部楼层

呵呵,当然,所有的函数都是人写出来的,别人可以,当然你也可以!
下面是个示意,希望能帮到你。
    ///
    /// 求两条曲线的交点,本函数为应对Polyline.IntersectWith函数的Bug
    /// Vrsion : 2009.02.10 Sieben
    /// Vrsion : 2010.12.25 增加判断输入实体是否为平面实体
    ///
    ///
    ///
    ///
    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;
      }
    }
回复

使用道具 举报

32

主题

651

帖子

8

银币

中流砥柱

Rank: 25

铜币
779
发表于 2011-3-29 12:08:00 | 显示全部楼层
///
    /// 求两两连线的交点
    ///
    /// 第一组点
    /// 第一组点
    /// 第二组点
    /// 第二组点
    /// 若有交点就返回交点,否则返回P11
    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);
      }
    }
注意,直线的交点和直线段的交点是有区别的
回复

使用道具 举报

6

主题

30

帖子

4

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
54
发表于 2011-3-31 16:29:00 | 显示全部楼层
回复
你是武大的?呵呵
回复

使用道具 举报

6

主题

30

帖子

4

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
54
发表于 2011-3-31 16:30:00 | 显示全部楼层
回复
谢谢sieben,对我来说很有用。
回复

使用道具 举报

0

主题

2

帖子

1

银币

初来乍到

Rank: 1

铜币
2
发表于 2013-10-29 11:47:00 | 显示全部楼层
非常感谢!
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-6-29 07:59 , Processed in 3.119707 second(s), 73 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表