%% Returns distance between two points (x1,z1) and (x2,z2) given by two-element arrays %% ====================================================================================== %% %% Parameters: %% p1, p2 - points. Each is given by two-element arrays containing x and y coordinates %% %% Returns: %% d - Euclidean distance between the points function d = distance(p1,p2) r = p2 - p1; d = sqrt(sum(r.*r)); % square root of dot product end