3

已知两个相交的 polyline 的坐标点集合,怎么求交点的精确坐标?坐标点不在点集里

 2 months ago
source link: https://www.v2ex.com/t/1028316
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

V2EX  ›  程序员

已知两个相交的 polyline 的坐标点集合,怎么求交点的精确坐标?坐标点不在点集里

  WangLiCha · 5 小时 56 分钟前 · 422 次点击

举例,多段线( polyline ) A 和 B 都由 4 个节点组成,A 的四个节点坐标为(1,1) (2,1) (3,4) (4,4),B 的四个节点坐标为(1,4) (2,2) (4,3) (3,1), 这两条线是存在一个交点的,怎么求这个交点的精确坐标?

PS:如果要求再提高,比如 B 的四个节点坐标为(1,4) (2,2) (4,3) (1,0),此时它们存在三个交点,怎么把他们都求出来?

9 条回复    2024-03-30 14:04:37 +08:00
hefish

hefish      5 小时 52 分钟前

穷举一下。 大不了就是求 12 对直线看相交不相交,相交的是否在线段上。
NessajCN

NessajCN      5 小时 39 分钟前 via Android

这不中学解几题吗…
用两组分段一元一次函数表示线段方程,
找出同定义域内是否存在解
kalinzhang

kalinzhang      5 小时 14 分钟前   ❤️ 1

顺时针遍历一个 polygon 的所有顶点,联立方程求交点即可。套现成的公式,算两个行列式就完事了。
如果要优化的话,可以先判断一下两个 polygon 是否可能相交(例如算下 AABB )再联立解方程,但其实解方程计算量也不大。
再扩展一下如果要做复杂 polygon 的相交测试的话,要考虑 polygon 是否有自交、是否是凹的、是否有多个 polygon 嵌套等情况,比较复杂了
rabbbit

rabbbit      5 小时 8 分钟前

https://paulbourke.net/geometry/pointlineplane/
往下翻 Intersection point of two line segments in 2 dimensions
SmiteChow

SmiteChow      4 小时 30 分钟前

shapely intersection result bound coords
akira

akira      2 小时 12 分钟前

2 条直线求相交点会吧
2 个线段求相交点会吧
1 个线段和 3 个 线段 分别求交点 会吧
3 个线段和 3 个 线段 分别求交点 会吧
那就做完了啊。。

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK