-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathCoord.py
84 lines (58 loc) · 2.03 KB
/
Coord.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import numpy as np
class CartCoord(object):
'''Creates a point on a Cartesian coordinate plane with values x and y.'''
def __init__(self, x: float, y: float):
'''Defines x and y variables'''
self.x = x
self.y = y
def __str__(self):
return "CartCoord(%s,%s)" % (self.getX(), self.getY())
def addCoord(self, other) -> None:
self.increment(other.getX(), other.getY())
def add(self, dx: float, dy: float) -> None:
self.x += dx
self.y += dy
def sub(self, dx: float, dy: float) -> None:
self.x -= dx
self.y -= dy
def scale(self, scaleFactor: float) -> None:
self.scaleX(scaleFactor)
self.scaleY(scaleFactor)
def scaleX(self, scaleFactor: float) -> None:
self.x *= scaleFactor
def scaleY(self, scaleFactor: float) -> None:
self.y *= scaleFactor
def getX(self) -> float:
return self.x
def getY(self) -> float:
return self.y
def getDistance(self, other) -> float:
dx = self.x - other.x
dy = self.y - other.y
return np.sqrt(dx**2 + dy**2)
def getAngle(self, other):
dx = self.x - other.x
dy = self.y - other.y
return np.arctan2(dy, dx)
def asTuple(self) -> tuple:
return (self.getX(), self.getY())
class PolarCoord(object):
'''Creates a point on a Cartesian coordinate plane with values x and y.'''
def __init__(self, r: float, theta: float):
'''Defines x and y variables'''
self.r = r
self.theta = theta
def __str__(self):
return "PolarCoord(%s,%s)" % (self.getR(), self.getTheta())
def getR(self) -> float:
return self.r
def getTheta(self) -> float:
return self.theta
def scaleR(self, scaleFactor) -> None:
self.r *= scaleFactor
def toCart(self) -> CartCoord:
x = self.r * np.cos(self.theta)
y = self.r * np.sin(self.theta)
return CartCoord(x, y)
def asTuple(self) -> tuple:
return (self.getR(), self.getTheta())