将自相交路径拆分为简单的非自相交路径

huangapple go评论51阅读模式
英文:

Split self-intersecting path into simple non-self-intersecting paths

问题

如何高效地将自相交的开放路径分割成多个简单的非自相交路径?

路径位于二维空间中,由连接的线段组成。它可以用一组点表示,其中第一个点是路径的起点,最后一个点是路径的终点(例如图片中的黑色路径)。

我正在使用Clipper2库来创建路径周围的缓冲区(图片中的蓝色轮廓是期望的结果),但Clipper.InflatePaths()不支持自相交的路径。因此,在创建缓冲区的中间步骤中,我需要将任何复杂(自相交的)路径分解为多个简单(非自相交的)路径(例如图片右侧的示例)。

  1. 将复杂路径分割成简单路径
  2. 在每个简单路径周围创建缓冲区(Clipper.InflatePaths()
  3. 合并所有缓冲区(Clipper.Union())以创建单个缓冲区多边形。
英文:

What is an efficient way to split a self-intersecting open path into multiple simple non-self-intersecting paths?

Path is in 2D space made of connected line segments. It can be represented by a collection of points, where the first point is a start of a path and the last point is an end of a path. (e.g. black path in the picture)

I'm using Clipper2 library to create a buffer around a path (blue outline in the picture is the desired outcome), but Clipper.InflatePaths() doesn't support self-intersecting paths. So, I need to break down any complex (self-intersecting) path into multiple simple (non-self-intersecting) paths (see right side of the picture for example), as an intermediate step of buffer creation.

  1. Split complex path to simple paths
  2. Create buffer around each simple path (Clipper.InflatePaths())
  3. Union all buffers (Clipper.Union()) to create a single buffer polygon.

将自相交路径拆分为简单的非自相交路径

答案1

得分: 1

有确实的方法可以做到你所要求的,但有更简单的方法来实现你想要的。

最简单的方法是分别膨胀每个线段,然后合并所有的结果。

下一个最简单的方法是分割路径,以保持沿路径行进的方向范围在180度内,因为结果路径不可能与自身相交。

英文:

There are certainly ways to do what you ask for, but there are easier ways to do what you want.

The easiest way is to inflate each line segment separately and then union all the results.

The next-easiest way is to break paths to keep the range of directions travelled along the path within 180 degrees, since it is impossible for resulting path to intersect itself.

huangapple
  • 本文由 发表于 2023年1月9日 18:18:05
  • 转载请务必保留本文链接:https://go.coder-hub.com/75055806.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定