Fix errors approximations in arc circle introducing gaps between ars in roads

This commit is contained in:
2024-06-21 00:55:33 +02:00
parent 92569d8815
commit 0eb47ac345
3 changed files with 67 additions and 59 deletions

101
main.py
View File

@@ -35,48 +35,48 @@ def main():
# editor.placeBlock( # editor.placeBlock(
# (c[1][i][j].x, 110, c[1][i][j].y), Block("red_concrete")) # (c[1][i][j].x, 110, c[1][i][j].y), Block("red_concrete"))
def place_segment(segment): # def place_segment(segment):
segment.segment_thick(30, LINE_THICKNESS_MODE.MIDDLE) # segment.segment_thick(30, LINE_THICKNESS_MODE.MIDDLE)
for i in range(len(segment.points_thick_by_line)): # for i in range(len(segment.points_thick_by_line)):
kk = i % 7 # kk = i % 7
match kk: # match kk:
case 0: # case 0:
blob = 'pink_concrete' # blob = 'pink_concrete'
case 1: # case 1:
blob = 'red_concrete' # blob = 'red_concrete'
case 2: # case 2:
blob = 'orange_concrete' # blob = 'orange_concrete'
case 3: # case 3:
blob = 'yellow_concrete' # blob = 'yellow_concrete'
case 4: # case 4:
blob = 'green_concrete' # blob = 'green_concrete'
case 5: # case 5:
blob = 'blue_concrete' # blob = 'blue_concrete'
case 6: # case 6:
blob = 'purple_concrete' # blob = 'purple_concrete'
for j in range(len(segment.points_thick_by_line[i])): # for j in range(len(segment.points_thick_by_line[i])):
editor.placeBlock(Point3D.insert_3d( # editor.placeBlock(Point3D.insert_3d(
[segment.points_thick_by_line[i][j]], 'y', [134])[0].coordinates, Block(blob)) # [segment.points_thick_by_line[i][j]], 'y', [134])[0].coordinates, Block(blob))
for i in range(len(segment.gaps)): # for i in range(len(segment.gaps)):
kk = i % 7 # kk = i % 7
match kk: # match kk:
case 0: # case 0:
blob = 'pink_concrete' # blob = 'pink_concrete'
case 1: # case 1:
blob = 'red_concrete' # blob = 'red_concrete'
case 2: # case 2:
blob = 'orange_concrete' # blob = 'orange_concrete'
case 3: # case 3:
blob = 'yellow_concrete' # blob = 'yellow_concrete'
case 4: # case 4:
blob = 'green_concrete' # blob = 'green_concrete'
case 5: # case 5:
blob = 'blue_concrete' # blob = 'blue_concrete'
case 6: # case 6:
blob = 'purple_concrete' # blob = 'purple_concrete'
for j in range(len(segment.gaps[i])): # for j in range(len(segment.gaps[i])):
editor.placeBlock(Point3D.insert_3d( # editor.placeBlock(Point3D.insert_3d(
[segment.gaps[i][j]], 'y', [135])[0].coordinates, Block(blob)) # [segment.gaps[i][j]], 'y', [135])[0].coordinates, Block(blob))
# place_segment(Segment2D(Point2D(147, -616), Point2D(132, -554))) # place_segment(Segment2D(Point2D(147, -616), Point2D(132, -554)))
# # place_segment(Segment2D(Point2D(147, -616), Point2D(117, -563))) # # place_segment(Segment2D(Point2D(147, -616), Point2D(117, -563)))
@@ -87,32 +87,29 @@ def main():
# # place_segment(Segment2D(Point2D(147, -616), Point2D(195, -665))) # # place_segment(Segment2D(Point2D(147, -616), Point2D(195, -665)))
# # place_segment(Segment2D(Point2D(147, -616), Point2D(204, -622))) # # place_segment(Segment2D(Point2D(147, -616), Point2D(204, -622)))
# # place_segment(Segment2D(Point2D(147, -616), Point2D(178, -575))) # # place_segment(Segment2D(Point2D(147, -616), Point2D(178, -575)))
x = 200
# place_segment(Segment2D(Point2D(0+x, 0), Point2D(50+x, 0))) # place_segment(Segment2D(Point2D(0+x, 0), Point2D(50+x, 0)))
# place_segment(Segment2D(Point2D(0+x, 0), Point2D(50+x, 25))) # place_segment(Segment2D(Point2D(0+x, 0), Point2D(50+x, 25)))
# place_segment(Segment2D(Point2D(0+x, 0), Point2D(50+x, 50))) # place_segment(Segment2D(Point2D(0+x, 0), Point2D(50+x, 50)))
place_segment(Segment2D(Point2D(0+x, 0), Point2D(25+x, 50))) # place_segment(Segment2D(Point2D(0+x, 0), Point2D(25+x, 50)))
# place_segment(Segment2D(Point2D(0+x, 0), Point2D(0+x, 50))) # place_segment(Segment2D(Point2D(0+x, 0), Point2D(0+x, 50)))
place_segment(Segment2D(Point2D(0+x, 0), Point2D(-25+x, 50))) # place_segment(Segment2D(Point2D(0+x, 0), Point2D(-25+x, 50)))
# place_segment(Segment2D(Point2D(0+x, 0), Point2D(-50+x, 50))) # place_segment(Segment2D(Point2D(0+x, 0), Point2D(-50+x, 50)))
# place_segment(Segment2D(Point2D(0+x, 0), Point2D(-50+x, 25))) # place_segment(Segment2D(Point2D(0+x, 0), Point2D(-50+x, 25)))
# place_segment(Segment2D(Point2D(0+x, 0), Point2D(-50+x, 0))) # place_segment(Segment2D(Point2D(0+x, 0), Point2D(-50+x, 0)))
# place_segment(Segment2D(Point2D(0+x, 0), Point2D(-50+x, -25))) # place_segment(Segment2D(Point2D(0+x, 0), Point2D(-50+x, -25)))
# place_segment(Segment2D(Point2D(0+x, 0), Point2D(-50+x, -50))) # place_segment(Segment2D(Point2D(0+x, 0), Point2D(-50+x, -50)))
place_segment(Segment2D(Point2D(0+x, 0), Point2D(-25+x, -50))) # place_segment(Segment2D(Point2D(0+x, 0), Point2D(-25+x, -50)))
# place_segment(Segment2D(Point2D(0+x, 0), Point2D(0+x, -50))) # place_segment(Segment2D(Point2D(0+x, 0), Point2D(0+x, -50)))
place_segment(Segment2D(Point2D(0+x, 0), Point2D(25+x, -50))) # place_segment(Segment2D(Point2D(0+x, 0), Point2D(25+x, -50)))
# place_segment(Segment2D(Point2D(0+x, 0), Point2D(50+x, -50))) # place_segment(Segment2D(Point2D(0+x, 0), Point2D(50+x, -50)))
# place_segment(Segment2D(Point2D(147, -616), Point2D(201, -595))) # place_segment(Segment2D(Point2D(147, -616), Point2D(201, -595)))
# place_segment(Segment2D(Point2D(147, -616), Point2D(233, -605))) # place_segment(Segment2D(Point2D(147, -616), Point2D(233, -605)))
y = 105 y = 120
# Road([Point3D(121, 108+y, -68), Point3D(163, 108+y, -95), Point3D(173, 108+y, -169), Point3D(188, 108+y, -174), Point3D(229, Road([Point3D(121, 108+y, -68), Point3D(163, 108+y, -95), Point3D(173, 108+y, -169), Point3D(188, 108+y, -174), Point3D(229,
# 108+y, -217), Point3D(190, 95+y, -270), Point3D(198, 95+y, -297), Point3D(237, 95+y, -287), Point3D(283, 95+y, -328)], 15) 108+y, -217), Point3D(190, 95+y, -270), Point3D(198, 95+y, -297), Point3D(237, 95+y, -287), Point3D(283, 95+y, -328)], 15)
# Road([Point3D(464, 85+10, -225), Point3D(408, 105+10, -224), # Road([Point3D(464, 85+10, -225), Point3D(408, 105+10, -224),
# Point3D(368, 104+10, -249), Point3D(368, 85+10, -296), Point3D(457, 79+10, -292)], 15) # Point3D(368, 104+10, -249), Point3D(368, 85+10, -296), Point3D(457, 79+10, -292)], 15)

View File

@@ -102,12 +102,25 @@ class Polyline:
list[tuple(Point2D)]: List of tuples composed - in order - of the first arc points, the corner points, the last arc points. The corresponding arc circle is inside this triangle. list[tuple(Point2D)]: List of tuples composed - in order - of the first arc points, the corner points, the last arc points. The corresponding arc circle is inside this triangle.
""" """
for i in range(1, self.length_polyline-1): for i in range(1, self.length_polyline-1):
point_1 = Point2D.from_arrays(self.points_array[i] - point_1 = Point2D.from_arrays(self.points_array[i] -
self.alpha_radii[i] * self.unit_vectors[i-1]) self.alpha_radii[i] * self.unit_vectors[i-1])
point_2 = Point2D.from_arrays(self.points_array[i] + point_2 = Point2D.from_arrays(self.points_array[i] +
self.alpha_radii[i] * self.unit_vectors[i]) self.alpha_radii[i] * self.unit_vectors[i])
self.acrs_intersections[i] = point_1.round(), Point2D.from_arrays(
self.points_array[i]), point_2.round() # If Arc intersection are near, meaning no segment between, we need to remove error due to discrete appoximation.
# Instead of two independant arc intersection, we make sure to combine both.
if i > 1:
if point_1.distance(self.acrs_intersections[i-1][2]) <= 2:
print(point_1, self.acrs_intersections[i-1][2])
middle = Segment2D(
point_1, self.acrs_intersections[i-1][2]).middle_point()
print(middle)
point_1 = middle
self.acrs_intersections[i-1][2] = middle
self.acrs_intersections[i] = [point_1.round(), Point2D.from_arrays(
self.points_array[i]), point_2.round()]
return self.acrs_intersections return self.acrs_intersections
def get_arcs(self) -> List[Point2D]: def get_arcs(self) -> List[Point2D]:
@@ -142,7 +155,6 @@ class Polyline:
for i in range(2, self.length_polyline - 1): for i in range(2, self.length_polyline - 1):
self.segments[i] = Segment2D(Point2D( self.segments[i] = Segment2D(Point2D(
self.acrs_intersections[i-1][2].x, self.acrs_intersections[i-1][2].y), Point2D(self.acrs_intersections[i][0].x, self.acrs_intersections[i][0].y)) self.acrs_intersections[i-1][2].x, self.acrs_intersections[i-1][2].y), Point2D(self.acrs_intersections[i][0].x, self.acrs_intersections[i][0].y))
print(self.segments[i], i)
# Why -3? # Why -3?
# For n points, there are n-1 segments. # For n points, there are n-1 segments.

View File

@@ -247,7 +247,6 @@ class Segment2D:
index = -1 index = -1
else: else:
index = 0 index = 0
print(i)
del self.points_thick_by_line[index] del self.points_thick_by_line[index]
del self.gaps[index] del self.gaps[index]
@@ -276,9 +275,9 @@ class Segment2D:
return Point2D(x3, y3).round(), Point2D(x4, y4).round() return Point2D(x3, y3).round(), Point2D(x4, y4).round()
def middle_point(self): def middle_point(self):
return (np.round((self.start.x + self.end.x) / 2.0).astype(int), return Point2D(np.round((self.start.x + self.end.x) / 2.0).astype(int),
np.round((self.start.y + self.end.y) / 2.0).astype(int), np.round((self.start.y + self.end.y) / 2.0).astype(int),
) )
def _add_points(self, points, is_computing_thickness, overlap): def _add_points(self, points, is_computing_thickness, overlap):
if is_computing_thickness >= 0: if is_computing_thickness >= 0: