Fix intersection curved corners
This commit is contained in:
41
main.py
41
main.py
@@ -111,14 +111,12 @@ block_list = ["blue_concrete", "red_concrete", "green_concrete",
|
||||
# print(l.get_surface())
|
||||
|
||||
|
||||
# circle = curved_corner_intersection(
|
||||
# ((-1313, 392), (-1378, 415)), ((-1371, 348), (-1341, 439)), 30, angle_adaptation=True, output_only_points=False)
|
||||
circle = curved_corner_intersection(
|
||||
((-1365, 520), (-1326, 523)), ((-1344, 496), (-1336, 535)), 10, angle_adaptation=False, output_only_points=False)
|
||||
|
||||
# print(circle)
|
||||
|
||||
# for coordinate in circle[0]:
|
||||
# editor.placeBlock(
|
||||
# (round(coordinate[0]), 100, round(coordinate[1])), Block("green_concrete"))
|
||||
for coordinate in circle[0]:
|
||||
editor.placeBlock(
|
||||
(round(coordinate[0]), 125, round(coordinate[1])), Block("green_concrete"))
|
||||
|
||||
# ---
|
||||
|
||||
@@ -131,23 +129,23 @@ block_list = ["blue_concrete", "red_concrete", "green_concrete",
|
||||
|
||||
# ---
|
||||
|
||||
r1 = Road.Road((-1337, 71, 472), "None")
|
||||
r2 = Road.Road((-1269, 80, 574), "None")
|
||||
r3 = Road.Road((-1392, 79, 527), "None")
|
||||
# r1 = Road.Road((-1337, 71, 472), "None")
|
||||
# r2 = Road.Road((-1269, 80, 574), "None")
|
||||
# r3 = Road.Road((-1392, 79, 527), "None")
|
||||
|
||||
i = Intersection.Intersection(
|
||||
(-1327, 71, 533), [(-1335, 71, 494), (-1298, 75, 553), (-1366, 78, 530)], [r1, r2, r3])
|
||||
# i = Intersection.Intersection(
|
||||
# (-1327, 71, 533), [(-1335, 71, 494), (-1298, 75, 553), (-1366, 78, 530)], [r1, r2, r3])
|
||||
|
||||
# ---
|
||||
|
||||
# y = 100
|
||||
y = 150
|
||||
|
||||
# r1 = Road.Road((-1337, y, 472), "None")
|
||||
# r2 = Road.Road((-1269, y, 574), "None")
|
||||
# r3 = Road.Road((-1392, y, 527), "None")
|
||||
r1 = Road.Road((-1337, y, 472), "None")
|
||||
r2 = Road.Road((-1269, y, 574), "None")
|
||||
r3 = Road.Road((-1392, y, 527), "None")
|
||||
|
||||
# i = Intersection.Intersection(
|
||||
# (-1327, y, 533), [(-1335, y, 494), (-1298, y, 553), (-1366, y, 530)], [r1, r2, r3])
|
||||
i = Intersection.Intersection(
|
||||
(-1327, y, 533), [(-1335, y, 494), (-1298, y, 553), (-1366, y, 530)], [r1, r2, r3])
|
||||
|
||||
|
||||
i.compute_curved_corner()
|
||||
@@ -177,3 +175,10 @@ for j in range(len(i.orthogonal_delimitations)):
|
||||
for coordinate in i.intersections:
|
||||
if coordinate != None:
|
||||
editor.placeBlock(coordinate, Block("black_concrete"))
|
||||
|
||||
for k in range(len(i.intersections_curved)):
|
||||
for coordinate in i.intersections_curved[k][0]:
|
||||
if coordinate != None:
|
||||
if k >= 0:
|
||||
editor.placeBlock(
|
||||
(coordinate[0], y, coordinate[1]), Block("cyan_concrete"))
|
||||
|
||||
@@ -256,7 +256,7 @@ def circle_segment_intersection(
|
||||
(p1x, p1y), (p2x, p2y), (cx, cy) = (
|
||||
(xy0[0], xy0[-1]),
|
||||
(xy1[0], xy1[-1]),
|
||||
(circle_center[0], circle_center[1]),
|
||||
(circle_center[0], circle_center[-1]),
|
||||
)
|
||||
(x1, y1), (x2, y2) = (p1x - cx, p1y - cy), (p2x - cx, p2y - cy)
|
||||
dx, dy = (x2 - x1), (y2 - y1)
|
||||
@@ -314,8 +314,8 @@ def perpendicular(distance, xy1, xy2):
|
||||
tuple: Coordinates of the line length distance, perpendicular
|
||||
to [xy1; xy2] at xy1.
|
||||
"""
|
||||
(x1, y1) = xy1
|
||||
(x2, y2) = xy2
|
||||
(x1, y1) = xy1[0], xy1[-1]
|
||||
(x2, y2) = xy2[0], xy2[-1]
|
||||
dx = x1 - x2
|
||||
dy = y1 - y2
|
||||
dist = sqrt(dx * dx + dy * dy)
|
||||
@@ -329,7 +329,7 @@ def perpendicular(distance, xy1, xy2):
|
||||
|
||||
|
||||
def curved_corner_intersection(
|
||||
line0, line1, start_distance, angle_adaptation=False, full_line=False, center=(), output_only_points=True
|
||||
line0, line1, start_distance, angle_adaptation=False, full_line=True, center=(), output_only_points=True
|
||||
):
|
||||
"""
|
||||
Create points between the two lines to smooth the intersection.
|
||||
@@ -350,6 +350,8 @@ def curved_corner_intersection(
|
||||
|
||||
>>> curved_corner_intersection(((0, 0), (50, 20)), ((-5, 50), (25, -5)), 10)
|
||||
"""
|
||||
print("\nInput:")
|
||||
print(line0, line1)
|
||||
intersection = segments_intersection(line0, line1, full_line)
|
||||
|
||||
if intersection == None:
|
||||
@@ -370,20 +372,20 @@ def curved_corner_intersection(
|
||||
intersection, start_distance, line0[0], intersection, full_line
|
||||
)[0]
|
||||
start_curve_point = (
|
||||
round(start_curve_point[0]), round(start_curve_point[1]))
|
||||
round(start_curve_point[0]), round(start_curve_point[-1]))
|
||||
end_curve_point = circle_segment_intersection(
|
||||
intersection, start_distance, line1[0], intersection, full_line
|
||||
)[0]
|
||||
end_curve_point = (round(end_curve_point[0]), round(end_curve_point[1]))
|
||||
end_curve_point = (round(end_curve_point[0]), round(end_curve_point[-1]))
|
||||
# Higher value for better precision
|
||||
perpendicular0 = perpendicular(10e3, start_curve_point, intersection)[0]
|
||||
perpendicular1 = perpendicular(10e3, end_curve_point, intersection)[1]
|
||||
perpendicular1 = perpendicular(10e3, end_curve_point, intersection)[-1]
|
||||
|
||||
if center == ():
|
||||
center = segments_intersection(
|
||||
(perpendicular0, start_curve_point), (perpendicular1, end_curve_point)
|
||||
)
|
||||
center = round(center[0]), round(center[1])
|
||||
center = round(center[0]), round(center[-1])
|
||||
|
||||
# Distance with startCurvePoint and endCurvePoint from the center are the
|
||||
# same.
|
||||
@@ -408,4 +410,7 @@ def curved_corner_intersection(
|
||||
# Be sure that all the points are in correct order.
|
||||
curve_corner_points = optimized_path(
|
||||
curved_corner_points_temporary, start_curve_point)
|
||||
print("Output:")
|
||||
print(curve_corner_points)
|
||||
print("\n")
|
||||
return curve_corner_points, center, radius
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from networks.geometry.segment_tools import parallel, orthogonal
|
||||
from networks.geometry.point_tools import sort_by_clockwise, segments_intersection
|
||||
from networks.geometry.point_tools import sort_by_clockwise, segments_intersection, curved_corner_intersection
|
||||
from networks.roads import Road
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ class Intersection:
|
||||
self.parallel_delimitations = []
|
||||
self.orthogonal_delimitations = []
|
||||
self.intersections = []
|
||||
self.intersections_curved = []
|
||||
|
||||
def compute_curved_corner(self):
|
||||
# Necessary to test nearby intersection
|
||||
@@ -27,4 +28,18 @@ class Intersection:
|
||||
self.intersections.append(segments_intersection(
|
||||
self.parallel_delimitations[j][1], self.parallel_delimitations[(j+1) % len(self.Roads)][0], full_line=False))
|
||||
|
||||
print(self.intersections)
|
||||
test = tuple(self.parallel_delimitations[(
|
||||
j+1) % len(self.Roads)][0][0]), tuple(self.parallel_delimitations[(j+1) % len(self.Roads)][0][1])
|
||||
test0 = tuple(self.parallel_delimitations[j][1][0]), tuple(
|
||||
self.parallel_delimitations[j][1][1])
|
||||
|
||||
print("\n\n\n --- \n\n\n")
|
||||
print(self.parallel_delimitations)
|
||||
print(self.parallel_delimitations[(
|
||||
j+1) % len(self.Roads)][0])
|
||||
print(self.parallel_delimitations[j][1])
|
||||
|
||||
self.intersections_curved.append(curved_corner_intersection(
|
||||
((test0[0][0], test0[0][-1]), (test0[1][0], test0[1][-1])), ((test[0][0], test[0][-1]), (test[1][0], test[1][-1])), 10, angle_adaptation=False, output_only_points=False))
|
||||
|
||||
print("\n", test0, test)
|
||||
|
||||
Reference in New Issue
Block a user