forked from ndwork/dworkLib
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfindDistsBetweenPtsAndLine.m
More file actions
30 lines (27 loc) · 1.02 KB
/
findDistsBetweenPtsAndLine.m
File metadata and controls
30 lines (27 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
function dists = findDistsBetweenPtsAndLine( pts, line )
% dist = findDistBetweenPtsAndLine( pts, line )
%
% Inputs:
% pts - a MxN real array specifying the coordinates of the points
% M is the dimension of the space; N is the number of points
% line - a structure containing two elements: pt and vec
% line.pt is a point on the line
% line.vec is a vector that points in the direction of the line
%
% Outputs:
% dists - a 1D array representing the shortest distance between the points and the line
%
% Written by Nicholas Dwork - Copyright 2019
%
% https://github.com/ndwork/dworkLib.git
%
% This software is offered under the GNU General Public License 3.0. It
% is offered without any warranty expressed or implied, including the
% implied warranties of merchantability or fitness for a particular
% purpose.
a = line.pt; a = a(:);
n = line.vec; n = n(:);
aMinusP = bsxfun( @minus, a, pts );
tmp = bsxfun( @times, ( aMinusP' * n )', n );
dists = norms( aMinusP - tmp, 2, 1 );
end