Clean distance
This commit is contained in:
@@ -18,6 +18,8 @@ class Point2D:
|
|||||||
def is_in_triangle(self, xy0: Type[Point2D], xy1: Type[Point2D], xy2: Type[Point2D]):
|
def is_in_triangle(self, xy0: Type[Point2D], xy1: Type[Point2D], xy2: Type[Point2D]):
|
||||||
"""Returns True is the point is in a triangle defined by 3 others points.
|
"""Returns True is the point is in a triangle defined by 3 others points.
|
||||||
|
|
||||||
|
From: https://stackoverflow.com/questions/2049582/how-to-determine-if-a-point-is-in-a-2d-triangle#:~:text=A%20simple%20way%20is%20to,point%20is%20inside%20the%20triangle.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
xy0 (Type[Point2D]): Point of the triangle.
|
xy0 (Type[Point2D]): Point of the triangle.
|
||||||
xy1 (Type[Point2D]): Point of the triangle.
|
xy1 (Type[Point2D]): Point of the triangle.
|
||||||
@@ -26,7 +28,6 @@ class Point2D:
|
|||||||
Returns:
|
Returns:
|
||||||
bool: False if the point is not inside the triangle.
|
bool: False if the point is not inside the triangle.
|
||||||
"""
|
"""
|
||||||
# https://stackoverflow.com/questions/2049582/how-to-determine-if-a-point-is-in-a-2d-triangle#:~:text=A%20simple%20way%20is%20to,point%20is%20inside%20the%20triangle.
|
|
||||||
dx = self.x - xy0.x
|
dx = self.x - xy0.x
|
||||||
dy = self.y - xy0.y
|
dy = self.y - xy0.y
|
||||||
|
|
||||||
@@ -43,3 +44,6 @@ class Point2D:
|
|||||||
return (s_p >= 0) and (t_p >= 0) and (s_p + t_p) <= d
|
return (s_p >= 0) and (t_p >= 0) and (s_p + t_p) <= d
|
||||||
else:
|
else:
|
||||||
return (s_p <= 0) and (t_p <= 0) and (s_p + t_p) >= d
|
return (s_p <= 0) and (t_p <= 0) and (s_p + t_p) >= d
|
||||||
|
|
||||||
|
def distance(self, point: Type[Point2D]):
|
||||||
|
return sqrt((point.x - self.x) ** 2 + (point.y - self.y) ** 2)
|
||||||
|
|||||||
@@ -15,3 +15,6 @@ class Point3D:
|
|||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return f"Point2D(x: {self.x}, y: {self.y}, z: {self.z})"
|
return f"Point2D(x: {self.x}, y: {self.y}, z: {self.z})"
|
||||||
|
|
||||||
|
def distance(self, point: Type[Point3D]):
|
||||||
|
return sqrt((point.x - self.x) ** 2 + (point.y - self.y) ** 2 + (point.z - self.z) ** 2)
|
||||||
|
|||||||
Reference in New Issue
Block a user