mirror of
https://gitlab.science.ru.nl/mthesis-edeboone/m-thesis-introduction.git
synced 2024-12-22 11:33:32 +01:00
Simu: allow Locations to determine distances
This commit is contained in:
parent
01689f7b7e
commit
03b2ddf117
2 changed files with 15 additions and 3 deletions
|
@ -1,6 +1,12 @@
|
|||
import numpy as np
|
||||
from functools import partial
|
||||
|
||||
def distance(x1, x2):
|
||||
"""
|
||||
Calculate the Euclidean distance between two locations x1 and x2
|
||||
"""
|
||||
return np.sqrt( np.sum( (x1 - x2)**2, axis=0) )
|
||||
|
||||
class Location:
|
||||
"""
|
||||
A location is a point designated by a spatial coordinate x.
|
||||
|
@ -20,6 +26,12 @@ class Location:
|
|||
def __setitem__(self, key, val):
|
||||
self.x[key] = val
|
||||
|
||||
def distance(self, other):
|
||||
if isinstance(other, Location):
|
||||
other = other.x
|
||||
|
||||
return distance(self.x, other)
|
||||
|
||||
# math
|
||||
def __add__(self, other):
|
||||
if isinstance(other, Location):
|
||||
|
|
|
@ -43,9 +43,9 @@ class Signal():
|
|||
|
||||
raise NotImplementedError
|
||||
|
||||
def spatial_time_offset(self, x_f, velocity=None, x_0=None):
|
||||
def spatial_time_offset(self, x_f, x_0=None, velocity=None):
|
||||
"""
|
||||
Calculate the time offset caused by a spatial difference.
|
||||
Calculate the time offset caused by a spatial distance.
|
||||
"""
|
||||
if velocity is None:
|
||||
velocity = self.velocity
|
||||
|
@ -57,7 +57,7 @@ class Signal():
|
|||
|
||||
def temporal_time_offset(self, t_f, t_0=None):
|
||||
"""
|
||||
Calculate the time offset caused by a temporal difference.
|
||||
Calculate the time offset caused by a temporal distance.
|
||||
"""
|
||||
if t_0 is None:
|
||||
t_0 = self.t_0
|
||||
|
|
Loading…
Reference in a new issue