简体   繁体   English

2D几何:如何在给定内部点的情况下确定最接近的周围线?

[英]2D Geometry: How to determine the closest surrounding lines given an internal point?

I am looking to replicate the functionality provided by the AutoCAD BOUNDARY command. 我正在寻找复制AutoCAD BOUNDARY命令提供的功能。 Given a 2D point in a drawing, I need to find all the closest line segments that surround that point. 给定图纸中的2D点,我需要找到围绕该点的所有最接近的线段。

This image depicts a drawing with lines and a point located within the lines (the blue square). 此图像描绘了带有线和位于线内的点的图形(蓝色正方形)。 before boundary command 边界命令之前

This image depicts the same drawing with the desired output once the autocad boundary command has been run using that point. 一旦使用该点运行了autocad boundary命令,此图像就会以所需的输出描绘同一图形。 after boundary command 边界命令后

The autocad boundary command has located the closest lines surrounding the point and highlighted them. autocad boundary命令已找到该点周围最近的线并突出显示了它们。 I've been trying to achieve the same outcome in C# without relying on the autocad editor commands. 我一直在尝试在C#中实现相同的结果,而不依赖于autocad编辑器命令。 My only idea was some sort of flood fill algorithm but this seems very inefficient and verbose for what shouldn't really be a difficult problem to solve. 我唯一的想法是某种洪水填充算法,但是对于实际上不应该解决的难题而言,这似乎非常低效且冗长。

I'd very much appreciate any suggestions or pseudocode that could point me in the right direction. 我非常感谢能为我指明正确方向的任何建议或伪代码。

Thanks 谢谢

You can use the Editor.TraceBoundary() method. 您可以使用Editor.TraceBoundary()方法。

public unsafe DBObjectCollection TraceBoundary(Point3d seedPoint, bool detectIslands)

http://www.through-the-interface.typepad.com/through_the_interface/2010/06/tracing-a-boundary-defined-by-autocad-geometry-using-net.html http://www.through-the-interface.typepad.com/through_the_interface/2010/06/tracing-a-boundary-defined-by-autocad-geometry-using-net.html

You have not described how your segments are organized. 您尚未描述细分的组织方式。

Build a ray from given point in horizontal direction, find the first intersected segment. 从水平方向的给定点构建射线,找到第一个相交的线段。 Get upper end of that segment and determine what neighbor segment the first in clockwise order . 获取该段的上端,并确定哪个相邻段按顺时针顺序排列。 Continue with the second end of that segment and so on until the first segment is met again. 继续该段的第二个末端,依此类推,直到再次遇到第一个段。

What boundary command is doing is finding a 2d point inside a closed polygon. 边界命令正在做的是在一个闭合的多边形内找到一个2d点。 There are many algorithms that cover this (see here) . 有很多算法可以解决这个问题(请参阅此处) However, because you are saying your lines aren't grouped you have to break this into two steps. 但是,由于您说的是未将行分组,因此必须将其分为两个步骤。 First step is to detect if a line is part of a polygon shape and store all these polygons in your data. 第一步是检测线是否为多边形形状的一部分,并将所有这些多边形存储在数据中。 Next is to find the closest line that belongs to a polygon shape. 接下来是找到属于多边形形状的最近的线。 Once you detect that you have found your solution. 一旦检测到您已找到解决方案。 For finding nearset line segment to a point, a simple search will get you alot of results. 为了找到到点的近线段,简单的搜索将为您带来很多结果。

Good luck 祝好运

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM