more uebung 05
This commit is contained in:
parent
4c00a2c0b1
commit
5dfd0ea8cd
Binary file not shown.
@ -16,9 +16,6 @@ class Point:
|
||||
return Point(-self.__x__, -self.__y__)
|
||||
|
||||
def __add__(self, other):
|
||||
x = 0.0
|
||||
y = 0.0
|
||||
|
||||
if isinstance(other, Point):
|
||||
return Point(self.__x__ + other.__x__, self.__y__ + other.__y__)
|
||||
elif isinstance(other, int) or isinstance(other, float):
|
||||
@ -30,10 +27,7 @@ class Point:
|
||||
return self + other
|
||||
|
||||
def __sub__(self, other):
|
||||
if isinstance(other, Point) or isinstance(other, int) or isinstance(other, float):
|
||||
return self + (-other)
|
||||
else:
|
||||
raise ValueError("Operand must be Point, int or float.")
|
||||
return self + (-other)
|
||||
|
||||
def __rsub__(self, other):
|
||||
return self - other
|
||||
@ -66,14 +60,15 @@ p3 = Point (3, 2)
|
||||
p4 = 2 * p2 + p3 - 1
|
||||
p5 = p4.rot(math.pi / 2)
|
||||
|
||||
plt.plot(p1.get_x(), p1.get_y(), "orange", marker = "o")
|
||||
plt.plot(p2.get_x(), p2.get_y(), "green", marker = "o")
|
||||
plt.plot(p3.get_x(), p3.get_y(), "yellow", marker = "o")
|
||||
plt.plot(p4.get_x(), p4.get_y(), "purple", marker = "o")
|
||||
plt.plot(p5.get_x(), p5.get_y(), "purple", marker = "o")
|
||||
plt.plot(p1.get_x(), p1.get_y(), "orange", marker = "o", label = p1)
|
||||
plt.plot(p2.get_x(), p2.get_y(), "green", marker = "o", label = p2)
|
||||
plt.plot(p3.get_x(), p3.get_y(), "yellow", marker = "o", label = p3)
|
||||
plt.plot(p4.get_x(), p4.get_y(), "purple", marker = "o", label = 2 * p2 + p3 - 1)
|
||||
plt.plot(p5.get_x(), p5.get_y(), "purple", marker = "o", label = f"{p4} rotated 90°")
|
||||
|
||||
plt.title("Points")
|
||||
plt.xlabel("x")
|
||||
plt.ylabel("y")
|
||||
plt.legend()
|
||||
|
||||
plt.show()
|
||||
|
Loading…
Reference in New Issue
Block a user