简体   繁体   中英

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. Given a 2D point in a drawing, I need to find all the closest line segments that surround that point.

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. after boundary command

The autocad boundary command has located the closest lines surrounding the point and highlighted them. I've been trying to achieve the same outcome in C# without relying on the autocad editor commands. 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.

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

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. 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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