Description: CSMV calculates distances from a given set of points to a set of linear segments
SYNOPSIS: [squared_distances_to_segments I]=csmv(P,R,Q,to_plot) [squared_distances_to_segments I]=csmv(P,R,Q,...)
INPUT P,R : arrays of coordinates of 2n segment endpoints (i.e., if there are n segments considered in pdimensional Euclidean space, than P and R are nbyp matrices); the sizes of P and R should coincide; p should be greater than or equal to unity. Q : an array of coordinates corresponding to the set of m points from which distances to the segments PR are calculated (Q should therefore be an mbyp matrix). to_plot : (optional) graphical output. Any nonzero value would cause the graphical output. There will be no graphical output by default (if this parameter is not passed).
OUTPUT squared_distances_to_segments : an nbym matrix whose jth column contains n squared distance from the jth point of Q to the segments PR. I : a vector of m elements representing indices of the segments PR which are the closest to points from Q.
EXAMPLES (1D, 2D and 3D cases with graphical outputs)
1) segments and points on the line PR_segments = [10,10; 1,0; 2.3,1; 5,9; 10,10.2]; % note that PR do not have to be defined as directed segments! E.g. the third segment [2.3,1] in PR_segments is defined as an undirected segment. P = PR_segments(:,1); R = PR_segments(:,2); [squared_distances_to_segments I]=csmv(P,R,Q)
OR
[squared_distances_to_segments I]=csmv(P,R,Q,1); 2) plane P =[1 3; 4 6; 8 1; 3 7]
R = [0 1; 2 2; 3 1; 0.1 2]
Q =[4 1; 5 5; 1 3.5; 10 2; 10 2]
to_plot=1; [squared_distances_to_segments I]=csmv(P,R,Q,to_plot)
3) 3D space P =[ 1 3 5; 4 6 9; 8 1 9; 3 7 0]
R = [
0 1.0000 1; 2.0000 2.0000 2; 3.0000 1.0000 4; 0.1000 2.0000 7]
Q =[
4.0000 1.0000 0; 5.0000 5.0000 8; 1.0000 3.5000 3; 10.0000 2.0000 1; 10.0000 2.0000 1]
[squared_distances_to_segments I] = csmv(P,R,Q,1);
License: Freeware Related: points, nonzero, calculated, nbyp, and 3d, undirected, Array, mbyp, nbym, are the, greater, be no, default, calculates distances, Defined, be an, arrays, as an O/S:BSD, Linux, Solaris, Mac OS X File Size: 10.0 KB Downloads: 11

