查找线的交点并创建单独的线

时间:2019-12-07 21:18:56

标签: python numpy sympy intersection cad

我有一个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

1 个答案:

答案 0 :(得分:1)

尽管Python支持任意大小的整数,但是将两个高精度整数相除可得出有限精度的浮点数。因此,让我们考虑一下您的两个整数

>>> n,d=1647113117371448512892615841780535357281063,737059219536588389452555455100000000000

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

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

因此,即使您给出的示例不存在此问题,但“ 50-60”行案例中的某些示例还是有此问题。最简单的解决方法是将您要处理的一行字符串简化为符号,例如lines = sympify('''[[Line3D(Point3D(1/2,...))]'''))。这样会将整数比率转换为任意精度的有理数,并希望在绘制时不会对您造成精度损失。