Project a planar polyline on another polyline

Find a projection of a cartesian polyline on another polyline.
845 Downloads
Updated 13 May 2009

No License

%poly_poly_proj Project a planar polyline on another polyline.
%*******************************************************************************
% function: poly_poly_proj
% Description: Compute the distances (cross-ranges) from a set of points
% P <p(1), p(2), ..., p(m)> on a plane to the planar polyline
% V <v(1), v(2), ..., v(n)>, and the distances (ranges) from the
% projections of P on V to the first point of a segment containing
% the projected point. Planar polyline V is defined as a set of n-1
% segments connecting n ordered vertices v(1), v(2), ..., v(n) on a
% plane.
% In case when the shortest distance is to the vertex of the
% polyline (see p(2) in the picture below), the cross range
% cr(2) will be the distance to the vertex and the range will be
% the length of this segment (segment # 3)
%
% p(1)
% o p(m)
% | o
% cr(1)-> | p(k) /
% | o / <- cr(m)
% v(1) v(2) | cr(k)-> | /
% x---x | | v(n)/
% \ | x-->|--------x <- r(m) = 0
% \ | v(3) / r(k)
% v(3) x->|--------x r(2)
% |->| \ <-cr(2)
% r(1) \
% o p(2)
% Input:
% xp - x coordinates of the first polyline (vector of length m)
% yp - y coordinates of the first polyline (vector of length m)
% xv - x coordinates of the second polyline (vector of length n)
% yv - y coordinates of the second polyline (vector of length n)
% Output:
% rpv - vector (of length m) of distances (ranges) from the projections on
% the second polyline to the beginnings of the segments containing
% these projections
% crpv - vector (of length m) of distances (cross-ranges) from points of the
% first polyline (P) to a second polyline (V), defined as a minimal
% distance from each point of the first polyline to any segment of a
% second polyline. Note that cr is a signed value! The sign of
% cross range is determined using a local coordinate system, where
% X axis is along the rib k, from point v(k) to v(k+1), Z axis is
% out of plane, and Y axis completes the right-hand system. The
% sign of projected point's p(j) y coordinate will determine the
% cross-range sign for this point.
% y
% ^
% | o p(j)
% | /|
% | / | <- cr > 0
% |/ |
% x---|-------x--------------> x
% v(k) v(k+1)
% spv - total projected path length. Can be negative, if P and V are in the
% opposite directions
% xppv - vector of x coordinates of the first polyline projections on the
% second polyline
% yppv - vector of y coordinates of the first polyline projections on the
% second polyline
% jppv - indices of the first points in segments containing the projections
% (vector of length m). In the abovementioned example, this vector
% should be jpv = [2, 4, 5, 6]. Note that the shortest distances
% of points p(1), p(2) and p(4) are not to the second polyline's
% ribs, but to the verices.
% Routines:
% Revision history:
% 12/05/2009 - added dimension parameter to cross function-Michael Yoshpe
% 26/11/2008 - created by Michael Yoshpe
% Remarks:
% Based on routine p_poly_dist that computed the distance from point to
% polygon
%*******************************************************************************

Cite As

Michael Yoshpe (2024). Project a planar polyline on another polyline (https://www.mathworks.com/matlabcentral/fileexchange/24090-project-a-planar-polyline-on-another-polyline), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R13SP1
Compatible with any release
Platform Compatibility
Windows macOS Linux
Categories
Find more on Elementary Polygons in Help Center and MATLAB Answers

Community Treasure Hunt

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

Start Hunting!
Version Published Release Notes
1.2.0.0

Added usage example at the end of the header

1.0.0.0