• API
• FAQ
• Tools
• Archive
SHARE
TWEET

# Untitled

a guest May 22nd, 2019 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. import math
2.
3. class PositionVector:
4.
5.     __slots__ = ['x', 'y', 'metric']
6.
7.     def __init__(self, x, y, metric):
8.         self.x = x
9.         self.y = y
10.         self.metric = metric
11.
12.     def norm(self):
13.         if self.metric == math.inf:
14.             return max(abs(self.x), abs(self.y))
15.         else:
16.             return math.sqrt(math.pow(abs(self.x), self.metric) + math.pow(abs(self.y), self.metric))
17.
18.         return None
19.
20.     def isEq(self, posVector):
21.         if self.metric == posVector.metric:
22.             return True
23.         else:
24.             return False
25.
26.     def isLarger(self, posVector):
27.         if self.norm() > posVector.norm():
28.             return True
29.         else: return False
30.
31.     def __str__(self):
32.         print("Position vector at " + str(id(self)))
33.         print("(x, y) = (" + str(self.x) + ", " + str(self.y) + ")")
34.         print("L_" + str(self.metric) + " = " + str(self.norm()))
35.
36.         return ""
37.
38.     def __gt__(self, posVector):
39.         if self.isLarger(posVector) == True:
40.             return True
41.         else: return False
42.
43.     def __ge__(self, posVector):
44.         if self.norm() >= posVector.norm(): return True
45.         else: return False
46.
47.
48. A = PositionVector(69.03, 92.24, math.inf)
49. B = PositionVector(3, 3, 2)
50. C = PositionVector(4, 4, math.inf)
51. D = PositionVector(5, 5, 1)
52. E = PositionVector(3, 3, 2)
53.
54. print(B >= E)
55.
56. print(A)
57.
58. l = [A, B, C, D, E]
59. l.sort()
60. for x in l:
61.     print(x)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.
Not a member of Pastebin yet?