mirror of
https://gitlab.science.ru.nl/mthesis-edeboone/m-thesis-introduction.git
synced 2025-05-17 21:39:23 +02: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):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue