Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 35269
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T14:12:34+00:00 2026-05-10T14:12:34+00:00

I have 1 red polygon say and 50 randomly placed blue polygons – they

  • 0

I have 1 red polygon say and 50 randomly placed blue polygons – they are situated in geographical 2D space. What is the quickest/speediest algorithim to find the the shortest distance between a red polygon and its nearest blue polygon?

Bear in mind that it is not a simple case of taking the points that make up the vertices of the polygon as values to test for distance as they may not necessarily be the closest points.

So in the end – the answer should give back the closest blue polygon to the singular red one.

This is harder than it sounds!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T14:12:35+00:00Added an answer on May 10, 2026 at 2:12 pm

    I doubt there is better solution than calculating the distance between the red one and every blue one and sorting these by length.

    Regarding sorting, usually QuickSort is hard to beat in performance (an optimized one, that cuts off recursion if size goes below 7 items and switches to something like InsertionSort, maybe ShellSort).

    Thus I guess the question is how to quickly calculate the distance between two polygons, after all you need to make this computation 50 times.

    The following approach will work for 3D as well, but is probably not the fastest one:

    Minimum Polygon Distance in 2D Space

    The question is, are you willing to trade accuracy for speed? E.g. you can pack all polygons into bounding boxes, where the sides of the boxes are parallel to the coordinate system axes. 3D games use this approach pretty often. Therefor you need to find the maximum and minimum values for every coordinate (x, y, z) to construct the virtual bounding box. Calculating the distances of these bounding boxes is then a pretty trivial task.

    Here’s an example image of more advanced bounding boxes, that are not parallel to the coordinate system axes:

    Oriented Bounding Boxes – OBB

    However, this makes the distance calculation less trivial. It is used for collision detection, as you don’t need to know the distance for that, you only need to know if one edge of one bounding box lies within another bounding box.

    The following image shows an axes aligned bounding box:

    Axes Aligned Bounding Box – AABB

    OOBs are more accurate, AABBs are faster. Maybe you’d like to read this article:

    Advanced Collision Detection Techniques

    This is always assuming, that you are willing to trade precision for speed. If precision is more important than speed, you may need a more advanced technique.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some string, they looks like: div#title.title.top #main.main a.bold#empty.red They are similar to
Say I have three lists: a={1,5,10,15} b={2,4,6,8} and c={1,1,0,1,0} . I want a plot
I have made some code that creates a red border around an image when
I have following url: http://localhost.com/phpdemo/bid/tf/red ? This url redirects through This [ $route['tf/red?'] =
Since black red tree is a binary search tree I have decided to use
See working example at http://jsfiddle.net/xqwqH . I have a green div inside a red
I have a form with a button at the end like this: var simple_form_right
I have a web page with lots of framesets and frames (don't ask), and
I'm working on a feature that will allow a user to click onto a
Any idea to make an element in the page full screen? For example,a div

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.