# Calculation of distances from a given set of points to a set of segments (Scripts) 1.0

Average Rating
User Rating:
Visitors Rating:
My rating:

• Last update: 6 years ago
• Price: Free |
• Operating system: Linux, Mac OS X, Win All, BSD, Solaris
• Publisher: Andrei Bejan (2 other programs)
See full specifications

## Calculation of distances from a given set of points to a set of segments (Scripts) Publisher's description

### CSMV calculates distances from a given set of points to a set of linear segments

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 p-dimensional
Euclidean space, than P and R are n-by-p 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 m-by-p matrix).
to_plot : (optional) graphical output.
Any non-zero 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 n-by-m matrix whose j-th column
contains n squared distance from the j-th 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 (1-D, 2-D and 3-D 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) 3-D 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);

#### System Requirements:

MATLAB 7.8 (R2009a)
Program Release Status: Major Update
Program Install Support: Install and Uninstall

#### Calculation of distances from a given set of points to a set of segments (Scripts) Tags:

Click on a tag to find related softwares

## Most Popular

ASK, OOK, FSK, BPSK, QPSK, 8PSK modulation 1.1
ASK, OOK, FSK, BPSK, QPSK, 8PSK modulation contain several functions for digital modulation simulation