Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
It seems you are looking for an easy solution to a not-so-easy problem - maybe this doesn't exist.
Very simple way is that obtain all points in 1st polygon and check which point is inside of 2nd polygon. but this algorithm is not that good performance and stupid way I think.

This algorithm will give wrong results for e.g. the following two polygons, where two rectangles intersect each other but not a single of its vertices lies within the other rectangle.

+-+ | | +--+-+--+ | | | | +--+-+--+ | | +-+

A better and easy-to-implement check would be whether any two edges of the polygons intersect. Of course, you also need to take into account that polygons might share one or more vertices, or a vertex might sit exactly on an edge of another polygon.

For performance, follow the hint by Lanx to start with the bounding boxes (waaay faster than calculating surrounding circles, sorry, hippo). This will easily eliminate polygons which don't overlap, and also provide some polygons which must overlap. Looking at my example above, if the two rectangles are bounding boxes of arbitrary polygons, then these polygons overlap.

But for sure this isn't complete. For some types of polygons, a strategy could be to cut the polygons into pieces (that's what Math::Polygon::Tree does, and it uses Math::Geometry::Planar::GPC for the hard work) and then repeat checking whether the bounding boxes overlap. Below are some border cases to check any algorithm - but maybe you know that you don't have any of these:

+----------+ +------+ +------+ | | | | | | | +-------+ | | | | | | | | | | | | +--+ | | | | | | | | | | | | | | +--+ | | | +--+ | | | | | | | | | | +-------+ +-+--+-+ +-+--+-+ | | | | +----------+ +--+

In reply to Re: searching polygons not merged by haj
in thread searching polygons not merged by dideod.yang

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (1)
As of 2024-04-18 23:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found