distancecart#

[distxy, theta] = distancecart(x1, y1, x2, y2, CalcMethod, dispout)

Description#

Calculate distance from (x1,y1) to (x2,y2) on cartesian coordinate

Inputs#

x1

x of start point (first point)

y1

y of start point (first point)

x2

x of end point (last point)

y2

y of end point (last point)

CalcMethod=’1d’;
Distance calculation method
‘1d’: use 1d array
‘pdist2’: Use 2d distance function
‘vector’: Use vectorized distance
dispout=’no’;

Define to display outputs or not (‘yes’: display, ‘no’: not display)

Outputs#

distxy
Distance from (x1,y1) to (x2,y2)
returns M*N array where M=length(x1) and N=length(x2)
mth row associated with mth point in (x,y)
nth column is associated with nth point in (x2,y2)
theta
Angle from start point to end point in (Degree)
returns M*N array where M=length(x1) and N=length(x2)
mth row associated with mth point in (x,y)
nth column is associated with nth point in (x2,y2)

Examples#

x1(:,1)=10.*rand(100,1);
y1(:,1)=10.*rand(100,1);
x2=[2.5;5;7.5];
y2=[3;6;9];
[distxy,theta]=distancecart(x1,y1,x2,y2,'1d','yes');

x1(:,1)=10.*rand(100,1);
y1(:,1)=10.*rand(100,1);
x2(:,1)=100.*rand(10,1);
y2(:,1)=100.*rand(10,1);
[distxy,theta]=distancecart(x1,y1,x2,y2,'pdist2','yes');

References#