-
Notifications
You must be signed in to change notification settings - Fork 4
/
Location.py
39 lines (31 loc) · 954 Bytes
/
Location.py
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
37
38
39
import math as m
class Location(object):
def __init__(self, x, y):
"""x and y are floats"""
self.x = x
self.y = y
def getx(self):
return self.x
def gety(self):
return self.y
def distFrom(self, other):
ox = other.x
oy = other.y
xDist = self.x - ox
yDist = self.y - oy
return (xDist**2 + yDist**2)**0.5
def getLoc(self, theta, radius):
theta = m.pi*theta/180
newX = self.getx() + round(radius*(m.cos(theta)),3)
newY = self.gety() + round(radius*(m.sin(theta)),3)
return Location(newX, newY)
def __str__(self):
return '(' + str(self.x) + ', ' + str(self.y) + ')'
class Field(object):
def __init__(self):
self.nodes = {}
def addNode(self, node, loc):
if node in self.nodes:
raise ValueError('Duplicate node')
else:
self.nodes[node] = loc