-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathLocation.py
More file actions
42 lines (28 loc) · 1.04 KB
/
Copy pathLocation.py
File metadata and controls
42 lines (28 loc) · 1.04 KB
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
import math
import numpy as np
class Location(object):
def __init__(self, x, y, z):
self.x = x
self.y = y
self.z = z
def __str__(self):
return "(" + str(self.x) + ", " + str(self.y) + ", " + str(self.z) + ")"
def getTerrestrialLocation(self):
return [self.x, self.y]
def getLocation(self):
return [self.x, self.y, self.z]
def __cmp__(self, other):
if self.x == other.x and self.y == other.y and self.z == other.z:
return True
return False
@classmethod
def getEuclideanDistance2D(cls, loc1, loc2):
return math.sqrt((abs(loc1.x - loc2.x)**2) + (abs(loc1.y - loc2.y)**2))
@classmethod
def getRandomLocWithin(cls, x, y):
xLoc = np.random.uniform(low=0, high=x)
yLoc = np.random.uniform(low=0, high=y)
return Location(xLoc, yLoc, 200)
@classmethod
def getEuclideanDistance3D(self, loc1, loc2):
return math.sqrt((abs(loc1.x - loc2.x) ** 2) + (abs(loc1.y - loc2.y) ** 2) + (abs(loc1.z - loc2.z) ** 2))