-
Notifications
You must be signed in to change notification settings - Fork 3
/
distance_vector.py
executable file
·43 lines (36 loc) · 1.45 KB
/
distance_vector.py
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
31
32
33
34
35
36
37
38
39
40
41
42
43
import numpy as np
def distance_vector(x,y,total0_or_increment1=0):
"""
% (C) Nick Holschuh - Amherst College - 2022 ([email protected])
% This function takes in x and y coordinates and calculates either the
% cumulative distance along the line or the incremental distance between
% points.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% The inputs are as follows:
%
% x - x_coordinates for your input array
% y - y_coordinates for your input array
% total0_or_increment1 - the cumulative distance [0] or the incremental
% distance (1). If you select (1), the last distance
% value is assumed to be == the second to last value.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% The function returns the following objects:
%
% distvec - your array of distances, the same length as the input vector
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%
"""
if 'total0_or_increment1' not in locals():
total0_or_increment1 = 0
if 'y' not in locals():
y = np.zeros(len(x));
distvec = np.zeros(len(x))
dists = np.sqrt(np.diff(x)**2+np.diff(y)**2)
if total0_or_increment1 == 0:
distvec[1:] = np.cumsum(dists)
else:
distvec[:-1] = dists
distvec[-1] = distvec[-2]
return distvec