This commit is contained in:
2024-06-13 17:27:50 +02:00
parent d76f4aefa9
commit f82d02cd06
7 changed files with 115 additions and 178 deletions

View File

@@ -13,14 +13,12 @@ class Point3D:
def copy(self):
return Point3D(self.x, self.y, self.z)
def coordinates(self):
return (self.x, self.y, self.z)
def __repr__(self):
return f"Point3D(x: {self.x}, y: {self.y}, z: {self.z})"
def distance(self, point: "Point3D"):
return sqrt((point.x - self.x) ** 2 + (point.y - self.y) ** 2 + (point.z - self.z) ** 2)
def __eq__(self, other):
if isinstance(other, Point3D):
return self.x == other.x and self.y == other.y and self.z == other.z
def nearest(self, points: List["Point3D"]) -> "Point3D":
"""Return the nearest point. If multiple nearest point, returns the first in the list.
@@ -69,6 +67,9 @@ class Point3D:
self.coordinate = (self.x, self.y, self.z)
return self
def distance(self, point: "Point3D"):
return sqrt((point.x - self.x) ** 2 + (point.y - self.y) ** 2 + (point.z - self.z) ** 2)
@staticmethod
def to_vectors(points: List["Point3D"]):
vectors = []