【问题标题】:Find The Intersections of Lines and Create Seperate Lines查找线的交点并创建单独的线
【发布时间】:2020-04-01 11:03:19
【问题描述】:

我有一个 AutoCAD 绘图的轴列表。有点像:

[Line3D(Point3D(1647113117371448512892615841780535357281063/737059219536588389452555455100000000000,
                1366943276273750947371820063466288403112033/737059219536588389452555455100000000000,0),
        Point3D(26100284670260312636891118431/12305005361967700000000000,
                1189236919681/781250000, 0)), ...]

当我尝试绘制它们时,应该不同的线被绘制为同一条线。所以我得到的是this,而不是this。以下是一些示例行:

[Line3D(Point3D(1647113117371448512892615841780535357281063/737059219536588389452555455100000000000,
                1366943276273750947371820063466288403112033/737059219536588389452555455100000000000, 0),
        Point3D(26100284670260312636891118431/12305005361967700000000000,1189236919681/781250000, 0)),
 Line3D(Point3D(26100284670260312636891118431/12305005361967700000000000, 1189236919681/781250000, 0),
        Point3D(25165031213118241584901717751/12305005361967700000000000, 32496091107827/25000000000, 0)),
 Line3D(Point3D(41101789294162424289223442852282888370853/12972516184739051605249750292000000000,
                6691132495400952526204407114066106055714449/3567441950803239191443681330300000000000, 0),
        Point3D(1428208758971484993356170173/478363263194784800000000, 1189236919681/781250000, 0)),
 Line3D(Point3D(1428208758971484993356170173/478363263194784800000000, 1189236919681/781250000, 0),
        Point3D(6865969238483742249815501841/2391816315973924000000000, 32496091107827/25000000000, 0)),
 Line3D(Point3D(1647113117371448512892615841780535357281063/737059219536588389452555455100000000000,
                1366943276273750947371820063466288403112033/737059219536588389452555455100000000000, 0),
        Point3D(41101789294162424289223442852282888370853/12972516184739051605249750292000000000,
                6691132495400952526204407114066106055714449/3567441950803239191443681330300000000000, 0)),
 Line3D(Point3D(41101789294162424289223442852282888370853/12972516184739051605249750292000000000,
                6691132495400952526204407114066106055714449/3567441950803239191443681330300000000000, 0),
        Point3D(42856219552476685009520165509926367369987/21754044541659661721907121840000000000,
                1105918704715895215440142199637240956944223/598236224895640697352445850600000000000, 0)),
 Line3D(Point3D(26100284670260312636891118431/12305005361967700000000000, 1189236919681/781250000, 0),
        Point3D(1428208758971484993356170173/478363263194784800000000, 1189236919681/781250000, 0)),
 Line3D(Point3D(1428208758971484993356170173/478363263194784800000000, 1189236919681/781250000, 0),
        Point3D(3662923296227402176907170887/2001416543837740000000000, 1189236919681/781250000, 0)),
 Line3D(Point3D(25165031213118241584901717751/12305005361967700000000000, 32496091107827/25000000000, 0),
        Point3D(6865969238483742249815501841/2391816315973924000000000, 32496091107827/25000000000, 0)),
 Line3D(Point3D(6865969238483742249815501841/2391816315973924000000000, 32496091107827/25000000000, 0),
        Point3D(3472204942560698802701958357/2001416543837740000000000, 32496091107827/25000000000, 0)),
 Line3D(Point3D(42856219552476685009520165509926367369987/21754044541659661721907121840000000000,
                1105918704715895215440142199637240956944223/598236224895640697352445850600000000000, 0),
        Point3D(3662923296227402176907170887/2001416543837740000000000, 1189236919681/781250000, 0)),
 Line3D(Point3D(3662923296227402176907170887/2001416543837740000000000, 1189236919681/781250000, 0),
        Point3D(3472204942560698802701958357/2001416543837740000000000, 32496091107827/25000000000, 0))
 ]

First Image Second Image

【问题讨论】:

  • 分隔线的标准是什么?如果不画出来,我们怎么知道它们是相似的?有什么建议吗?
  • 不清楚问题是否与您给出的行一起出现。是问题下方的答案,还是与处理行的顺序有关。如果是订单,请给出一个有效的订单和一个失败的订单。
  • 如果点数超过 6 位数,对于任何类型的现实世界绘图,您都需要将它们视为重合。

标签: python numpy sympy intersection cad


【解决方案1】:

虽然 Python 支持任意大小的整数,但两个高精度整数的除法给出了一个有限精度的浮点数。所以让我们考虑你的两个整数

>>> n,d=1647113117371448512892615841780535357281063,737059219536588389452555455100000000000

让我们比较一下n/dn/(d+10^20)的比率:

>>> n/d == n/(d + 10**20)
True

因此,即使您提供的示例没有此问题,但“50-60”行案例中的某些示例可能存在。最简单的解决方法是对您正在处理的一串行进行符号化,例如线 = sympify('''[Line3D(Point3D(1/2, ...))]''').这会将整数比率转换为任意精度的有理数,并希望在绘图时不会丢失精度。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-02-15
    • 1970-01-01
    • 2016-12-22
    • 1970-01-01
    • 1970-01-01
    • 2017-12-13
    • 1970-01-01
    相关资源
    最近更新 更多