src.acoustools.Paths.Distances

 1import torch
 2from torch import Tensor
 3
 4import itertools, math
 5
 6
 7def distance(p1:Tensor, p2:Tensor) -> float:
 8    '''
 9    Computes the euclidian distance between two points\n
10    :param p1: First point
11    :param p2: Second point
12    :return: Distance
13    '''
14    return torch.sqrt(torch.sum((p2 - p1)**2)).real
15
16
17def total_distance(path: list[Tensor]):
18    total_dist = 0
19    distances = []
20    for p1, p2 in itertools.pairwise(path):
21        d = distance(p1,p2)
22        total_dist +=  d
23        distances.append(d)
24    
25    return total_dist, distances
26
27def target_distance_to_n(total_dist, max_distance):
28    n = total_dist / max_distance
29    return math.ceil(n)
def distance(p1: torch.Tensor, p2: torch.Tensor) -> float:
 8def distance(p1:Tensor, p2:Tensor) -> float:
 9    '''
10    Computes the euclidian distance between two points\n
11    :param p1: First point
12    :param p2: Second point
13    :return: Distance
14    '''
15    return torch.sqrt(torch.sum((p2 - p1)**2)).real

Computes the euclidian distance between two points

Parameters
  • p1: First point
  • p2: Second point
Returns

Distance

def total_distance(path: list[torch.Tensor]):
18def total_distance(path: list[Tensor]):
19    total_dist = 0
20    distances = []
21    for p1, p2 in itertools.pairwise(path):
22        d = distance(p1,p2)
23        total_dist +=  d
24        distances.append(d)
25    
26    return total_dist, distances
def target_distance_to_n(total_dist, max_distance):
28def target_distance_to_n(total_dist, max_distance):
29    n = total_dist / max_distance
30    return math.ceil(n)