Code covered by the BSD License  

Highlights from
Calculation of distances from a given set of points to a set of segments

4.5

4.5 | 2 ratings Rate this file 10 Downloads (last 30 days) File Size: 3.07 KB File ID: #28268
image thumbnail

Calculation of distances from a given set of points to a set of segments

by

 

22 Jul 2010 (Updated )

A fully vectorised calculation of distances from a given set of points to a set of segments.

| Watch this File

File Information
Description

 CSMV calculates distances from a given set of points to a set of linear segments
 
  SYNOPSIS: [squared_distances_to_segments I t]=csmv(P,R,Q,to_plot)
            [squared_distances_to_segments I t]=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 or equal than 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.
        t : an n-by-m matrix whose ij-th element is a real number between 0
        and 1 equal to |P(i,:)Qi*(j,:)|/|P(i,:)R(i,:)|, where Qi*(j,:) is the
        point on the segment P(i,:)R(i,:) closest to Q(j,:). Thus, for example, if
        P(i,:) is closest to Q(j,:), then t(i,j)=0; if R(i,:) is closest to
        Q(j,:), then t(i,j)=1.
 
  NOTE: (i) the dimensions of P and R should coincide!
        (ii) you may encounter an error if some points P and R coincide;
        this can be easily avoided by suitably changing the code - feel
        free to do so.

Acknowledgements

This file inspired Simple Map Matching Algorithm For Edges And Arcs.

MATLAB release MATLAB 7.8 (R2009a)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (4)
06 Dec 2011 leila

Does the tool specify whether closest point falls within the line segment or not?

20 Aug 2010 Ben  
31 Jul 2010 Andrei Bejan

Steve, thanks!

I think I should complete this function by considering the case p=1. Will do soon.

31 Jul 2010 Steve

This is exactly what I needed. Thanks very much, that's a great contribution.

Updates
22 Jul 2010

Small changes in the description of this function have been made.

23 Jul 2010

minor corrections in the description of the function csmv

20 Aug 2010

one-dimensional case is added (p=1)

13 Dec 2011

A third output argument is added. This explicitly indicates whether the closest points on the segments are inner points or the end points.

Contact us