View License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from
Minimum distance between two polygons

Join the 15-year community celebration.

Play games and win prizes!

» Learn more

4.25
4.2 | 4 ratings Rate this file 14 Downloads (last 30 days) File Size: 9.73 KB File ID: #22444 Version: 1.2
image thumbnail

Minimum distance between two polygons

by

 

15 Dec 2008 (Updated )

This function computes the minimum euclidean distance between two polygons P1 & P2.

| Watch this File

File Information
Description

This function computes the minimum euclidean distance between two
polygons P1 & P2.

min_d = min_dist_between_two_polygons(P1,P2,Display_solution);

This function takes two arguments, a third one is optional.
  P1 & P2 contain the geometry of polygons.
  P1 & P2 are structures containing two fields: x & y
  For example:
        P1.x = rand(1,5)+2;
        P1.y = rand(1,5);
        P2.x = rand(1,3);
        P2.y = rand(1,3);
  Display_solution is a binary variable that enables or not the
  plot of the solution.

The function starts by checking if polygons are intersecting.
In this case, the minimum distance is 0.
Otherwise, distances between all vertices and edges of the two
polygons are computed. The function returns the minimum distance found.
Further details of the implementation can be found in the code.

Acknowledgements

Curve Intersect 2 inspired this file.

This file inspired Minimum Distance Between Two Polygons.

MATLAB release MATLAB 7 (R14)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (5)
27 Feb 2016 Solomon

This can be done in o(logm + logN) time, yours is done in n*m, the slowest possible calculation

16 Jan 2013 Sarhat

Sarhat (view profile)

hello

I found your function great, especially for object analysis in binary images. Can I as you only about how to extract the points(x,y) belong to both polygons that make the min distance

Regards

Comment only
20 Jan 2011 Moshe Lindner

Moshe Lindner (view profile)

great function!

15 Dec 2010 sjye

sjye (view profile)

 
16 Dec 2008 Diego Barragán

Diego Barragán (view profile)

 
Updates
15 Dec 2008 1.1

Some boundary cases have been taken into account.

16 Dec 2008 1.2

Some boundary cases have been taken into account.

Contact us