mirror of
https://gitlab.science.ru.nl/mthesis-edeboone/m-thesis-introduction.git
synced 2024-11-13 10:03: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
|
import numpy as np
|
||||||
from functools import partial
|
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:
|
class Location:
|
||||||
"""
|
"""
|
||||||
A location is a point designated by a spatial coordinate x.
|
A location is a point designated by a spatial coordinate x.
|
||||||
|
@ -20,6 +26,12 @@ class Location:
|
||||||
def __setitem__(self, key, val):
|
def __setitem__(self, key, val):
|
||||||
self.x[key] = val
|
self.x[key] = val
|
||||||
|
|
||||||
|
def distance(self, other):
|
||||||
|
if isinstance(other, Location):
|
||||||
|
other = other.x
|
||||||
|
|
||||||
|
return distance(self.x, other)
|
||||||
|
|
||||||
# math
|
# math
|
||||||
def __add__(self, other):
|
def __add__(self, other):
|
||||||
if isinstance(other, Location):
|
if isinstance(other, Location):
|
||||||
|
|
|
@ -43,9 +43,9 @@ class Signal():
|
||||||
|
|
||||||
raise NotImplementedError
|
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:
|
if velocity is None:
|
||||||
velocity = self.velocity
|
velocity = self.velocity
|
||||||
|
@ -57,7 +57,7 @@ class Signal():
|
||||||
|
|
||||||
def temporal_time_offset(self, t_f, t_0=None):
|
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:
|
if t_0 is None:
|
||||||
t_0 = self.t_0
|
t_0 = self.t_0
|
||||||
|
|
Loading…
Reference in a new issue