Distance from points to polyline or polygon

Find minimum distances from points to a polyline or to a closed polygon
6,2K descargas
Actualizado 25 may 2021

Ver licencia

Nota del editor: This file was selected as MATLAB Central Pick of the Week

The following files are included:
p_poly_dist.m - Compute the distances from each one of a set of np points p(1), p(2),... p(np) on a 2D plane to a polyline or a closed polygon. Polyline is defined as a set of nv-1 segments connecting nv ordered vertices v(1), v(2), ..., v(nv). The polyline can optionally be treated as a closed polygon.
Distance from point j to a segment k is defined as a distance from this point to a straight line passing through vertices v(k) and v(k+1), when the projection of point j on this line falls INSIDE of segment k; and to the closest of v(k) or v(k+1) vertices, when the projection falls OUTSIDE of segment k. Distance from point j to a polyline is defined as a minimum of this point's distances to all segments.
In a case when the projected point fall OUTSIDE of ALL polyline segments, the distance to a closest vertex of the polyline is returned
test_p_poly_dist.m - a simple unit test for p_poly_dist. Plots the results of a call to p_poly_dist function (see help for usage example)
p_poly_dist1.m – previous version (ver. 1.0) of p_poly_dist.m
Notes on version 2.0:
Oct 2, 2015 - version 2.0 (Michael Yoshpe). The original ver. 1.0 function was completely redesigned. The main changes introduced in Ver. 2.0 are:
1. Distances to polyline (instead of a closed polygon in Ver. 1.0) are returned. The polyline can optionally be treated as a closed polygon.
2. Distances from multiple points to the same polyline can be found.
3. The algorithm for finding the closest points is now based on coordinate system transformation. The new algorithm avoids numerical problems that Ver. 1.0 algorithm could experience in "ill-conditioned" cases.
4. Many optional output variables were added. In particular, the closest points on polyline can be returned.
5. Added input validity checks

Citar como

Michael Yoshpe (2024). Distance from points to polyline or polygon (https://www.mathworks.com/matlabcentral/fileexchange/12744-distance-from-points-to-polyline-or-polygon), MATLAB Central File Exchange. Recuperado .

Compatibilidad con la versión de MATLAB
Se creó con R2014b
Compatible con cualquier versión
Compatibilidad con las plataformas
Windows macOS Linux
Categorías
Más información sobre Elementary Polygons en Help Center y MATLAB Answers.

Community Treasure Hunt

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

Start Hunting!
Versión Publicado Notas de la versión
2.0.0.1

1) Small changes to p_poly_dist function to allow translation with Matlab Coder
2) Added run_test_p_poly_dist script that runs the unit test and plots the results

2.0.0.0

Fixed a bug that cause idx_c output argument to be off by 1
minor changes
Version 2.0 of the original function. See release notes in Description section. Previous version is also included (p_poly_dist1.m file)

1.0.0.0