File Exchange

image thumbnail

Minimum distance between two polygons

version 1.2.0.0 (9.73 KB) by Guillaume JACQUENOT
This function computes the minimum euclidean distance between two polygons P1 & P2.

2 Downloads

Updated 16 Dec 2008

View Version History

View License

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.

Cite As

Guillaume JACQUENOT (2020). Minimum distance between two polygons (https://www.mathworks.com/matlabcentral/fileexchange/22444-minimum-distance-between-two-polygons), MATLAB Central File Exchange. Retrieved .

Comments and Ratings (6)

xinglong fang

great function!

Solomon

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

Sarhat

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

moshe lindner

great function!

sjye

Diego Barragán

MATLAB Release Compatibility
Created with R14
Compatible with any release
Platform Compatibility
Windows macOS Linux
Acknowledgements

Inspired by: Curve Intersect 2

Inspired: Minimum distance between two polygons

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

min_dist_between_two_polygons/