如何通过相交线段分割 PathGeometry 多边形
我有一个由一堆 LineSegment 构建的 PathGeometry,我想将其分成两个 PathGeometry,并用一条与几何图形中间相交的线划分。这就是我对这张图片的意思:
http://i30.tinypic.com/2noyvm.png
我可以遍历 LineSegments 并创建一组简单的线对象(带有 Point1、Point2 属性的简单对象,以便它代表一条线)。但我需要以某种方式找出哪些线位于相交线的一端,哪些线位于相交线的另一端......
这有点像几何组合方法的相反,类似于几何我正在尝试组合的除法方法。
有什么想法吗?
谢谢!
I've got a PathGeometry that I've built from a bunch of LineSegments, and I want to split it into two PathGeometries divided by a line intersecting down the middle of the geometry. Here's what I mean by this picture:
http://i30.tinypic.com/2noyvm.png
I can go through the LineSegments and create an array of simple line objects (simple object w/ a Point1, Point2 property so that it represents one line). But i need to somehow figure out which Lines were on one end of the intersect line, and which lines were on the other end of the intersect line...
This is sort of like the opposite of a geometry combine method, something like a geometry divide method that I'm trying to put together.
Any ideas?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
确定哪些线位于相交线的哪一侧的方法是计算线端点相对于相交线的行列式的符号。积极的是一方面,消极的是另一方面。
如果您想要在线段内部实现更复杂的交集,那么您需要构建双向边和顶点的图,并计算相交线和每个多边形边的交集。然后,您可以在线与边相交的位置插入顶点,并回溯图形,当您沿着一个边到另一个边时,从有向边构建一个多边形。
如果您正在寻找此方法的实现,请查看 Net Topology Suite,主要用于 GIS,对于像这样的一般计算几何问题也很有用。
The way to figure out which lines are on which side of the intersection line is to compute the sign of the determinant of the line endpoints relative to the intersection line. Positive is one side, negative is the other.
If you want to have more sophisticated intersection, say, within the interior of a line-segment, then you need to build a graph of doubly-directed edges and vertexes and compute the intersection of the intersecting line and each polygon edge. You then insert vertexes where the line intersects edges and retrace the graph, building a polygon from the directed edges as you follow one to the other.
If you are looking for an implementation of this, check out Net Topology Suite, which, while used primarily for GIS, is also useful for general computational-geometry problems like this.
嗯,这很有趣,这就是我所做的(老实说,我不知道这是否是“正确”的方式,是否有更有效的方式)。
下面是一个 SplitGeometry 方法,它采用一个几何图形和一条由两点定义的线并返回两个几何图形:
Well, that was fun, here's what I did (I honestly have no idea if this is the "right" way of if there is a more efficient way).
Here's a SplitGeometry method that takes a geometry and a line defined by two points and returns the two geometries: