Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import math
- class PositionVector:
- __slots__ = ['x', 'y', 'metric']
- def __init__(self, x, y, metric):
- self.x = x
- self.y = y
- self.metric = metric
- def norm(self):
- if self.metric == math.inf:
- return max(abs(self.x), abs(self.y))
- else:
- return math.sqrt(math.pow(abs(self.x), self.metric) + math.pow(abs(self.y), self.metric))
- return None
- def isEq(self, posVector):
- if self.metric == posVector.metric:
- return True
- else:
- return False
- def isLarger(self, posVector):
- if self.norm() > posVector.norm():
- return True
- else: return False
- def __str__(self):
- print("Position vector at " + str(id(self)))
- print("(x, y) = (" + str(self.x) + ", " + str(self.y) + ")")
- print("L_" + str(self.metric) + " = " + str(self.norm()))
- return ""
- def __gt__(self, posVector):
- if self.isLarger(posVector) == True:
- return True
- else: return False
- def __ge__(self, posVector):
- if self.norm() >= posVector.norm(): return True
- else: return False
- A = PositionVector(69.03, 92.24, math.inf)
- B = PositionVector(3, 3, 2)
- C = PositionVector(4, 4, math.inf)
- D = PositionVector(5, 5, 1)
- E = PositionVector(3, 3, 2)
- print(B >= E)
- print(A)
- l = [A, B, C, D, E]
- l.sort()
- for x in l:
- print(x)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement