JTS中如何判断一条线是否相交?
有什么方法可以找出 JTS 中的 LineString 是否与自身相交?就像下图一样,我怎样才能找到这条线是否与自身相交?我通过给出 4 个边的坐标来创建该线。
提前致谢。
Is there any way to find out if a LineString intersects itself in JTS? Like in the following image how can i find if the line intersects itself? I am creating that line by just giving coordinates of its 4 edges.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
没有一条线可以与自身相交。你没有“一条线”;你有四行。您想看看其中两个是否彼此相交。
您可以显式计算交集或查看坐标的标记方式。如果从右下角开始,逆时针将点编号为 A、B、C 和 D,如果有直线连接 AC 和 BD,您会发现有一个交点。如果它们连接 AB、BC、CD 和 DA,则除了公共点之外不可能有交叉点。
No line can intersect itself. You don't have "a line"; you have four lines. You want to see if two of them intersect each other.
You can either calculate the intersection explicitly or look at how the coordinates are labeled. If you start in the lower right and number the points as A, B, C, and D by going counterclockwise, you can see that you have an intersection if there are lines connect AC and BD. If they connect AB, BC, CD, and DA there's no intersection possible except at the common points.
如果 LineString 像这样相交,
isSimple()
将返回false
,因为简单几何图形不允许自相交。If a LineString intersects like that,
isSimple()
will returnfalse
as self-intersection is not allowed for Simple Geometries.