Working first step projection

This commit is contained in:
2024-06-15 22:44:52 +02:00
parent 6564b5513a
commit 0dc29bc7c7
5 changed files with 14 additions and 9 deletions

View File

@@ -306,15 +306,15 @@ random_points = [Point2D(random.randint(min_val, max_val), random.randint(
# random_points = [Point2D(-40, -56), Point2D(-94, 92), Point2D(19, -47), Point2D( # random_points = [Point2D(-40, -56), Point2D(-94, 92), Point2D(19, -47), Point2D(
# 100, 59), Point2D(-85, -73), Point2D(-33, -9), Point2D(57, -25), Point2D(51, -34)] # 100, 59), Point2D(-85, -73), Point2D(-33, -9), Point2D(57, -25), Point2D(51, -34)]
# random_points = random_points[0].optimized_path(random_points) random_points = random_points[0].optimized_path(random_points)
# print(random_points) print(random_points)
# random_points = [Point2D(94, 71), Point2D(-12, 54), Point2D(-28, 10), Point2D( # random_points = [Point2D(94, 71), Point2D(-12, 54), Point2D(-28, 10), Point2D(
# 0, -33), Point2D(80, -50), Point2D(73, -89), Point2D(-86, -3), Point2D(-82, 92)] # 0, -33), Point2D(80, -50), Point2D(73, -89), Point2D(-86, -3), Point2D(-82, 92)]
random_points = [Point2D(-59, -21), Point2D(-43, -19), Point2D(-61, 19), Point2D( # random_points = [Point2D(-59, -21), Point2D(-43, -19), Point2D(-61, 19), Point2D(
45, 19), Point2D(80, -4), Point2D(99, 2), Point2D(47, 63), Point2D(100, -91)] # 45, 19), Point2D(80, -4), Point2D(99, 2), Point2D(47, 63), Point2D(100, -91)]
p = Polyline(random_points) p = Polyline(random_points)

View File

@@ -72,7 +72,7 @@ class Point2D:
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 nearest(self, points: List["Point2D"]) -> "Point2D": def nearest(self, points: List["Point2D"], return_index: bool = False) -> Union["Point2D", List[Union["Point2D", int]]]:
"""Return the nearest point. If multiple nearest point, returns the first in the list. """Return the nearest point. If multiple nearest point, returns the first in the list.
Args: Args:
@@ -81,6 +81,9 @@ class Point2D:
Returns: Returns:
Point2D: The nearest point, and if multiple, the first in the list. Point2D: The nearest point, and if multiple, the first in the list.
""" """
if return_index:
return min(
enumerate(points), key=lambda pair: self.distance(pair[1]))
return min(points, key=lambda point: self.distance(point)) return min(points, key=lambda point: self.distance(point))
def optimized_path(self, points: List["Point2D"]) -> List["Point2D"]: def optimized_path(self, points: List["Point2D"]) -> List["Point2D"]:

View File

@@ -61,7 +61,6 @@ class Polyline:
self.get_arcs_intersections() self.get_arcs_intersections()
self.get_arcs() self.get_arcs()
self.get_segments() self.get_segments()
print("\nlekj\n", self.segments, "\nklj\n")
self.total_line_output = [] self.total_line_output = []
for i in range(1, self.length_polyline-1): for i in range(1, self.length_polyline-1):

View File

@@ -52,9 +52,12 @@ class Road:
def _projection(self): def _projection(self):
nearest_points_to_reference = [] nearest_points_to_reference = []
for i in range(len(self.coordinates)): for i in range(len(self.coordinates)):
nearest_points_to_reference.append(Point3D.insert_3d([Point3D.to_2d([self.coordinates[i]], 'y')[0].nearest( # nearest_points_to_reference.append(Point3D.insert_3d([Point3D.to_2d([self.coordinates[i]], 'y')[0].nearest(
self.polyline.total_line_output)], 'y', [self.coordinates[i].y])[0]) # self.polyline.total_line_output, return_index=True)], 'y', [self.coordinates[i].y])[0])
print(nearest_points_to_reference) index, point = Point3D.to_2d([self.coordinates[i]], 'y')[0].nearest(
self.polyline.total_line_output, return_index=True)
nearest_points_to_reference.append(
Point2D(index, self.coordinates[i].y))
def place(self): def place(self):
editor = Editor(buffering=True) editor = Editor(buffering=True)

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.6 KiB

After

Width:  |  Height:  |  Size: 3.8 KiB