Fix segment small offset with thickness
This commit is contained in:
55
main.py
55
main.py
@@ -36,7 +36,7 @@ def main():
|
||||
# (c[1][i][j].x, 110, c[1][i][j].y), Block("red_concrete"))
|
||||
|
||||
def place_segment(segment):
|
||||
segment.segment_thick(4, LINE_THICKNESS_MODE.MIDDLE)
|
||||
segment.segment_thick(30, LINE_THICKNESS_MODE.MIDDLE)
|
||||
for i in range(len(segment.points_thick_by_line)):
|
||||
kk = i % 7
|
||||
match kk:
|
||||
@@ -79,34 +79,41 @@ def main():
|
||||
[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(117, -563)))
|
||||
# place_segment(Segment2D(Point2D(147, -616), Point2D(97, -576)))
|
||||
# place_segment(Segment2D(Point2D(147, -616), Point2D(71, -625)))
|
||||
# place_segment(Segment2D(Point2D(147, -616), Point2D(115, -655)))
|
||||
# place_segment(Segment2D(Point2D(147, -616), Point2D(162, -682)))
|
||||
# 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(178, -575)))
|
||||
# # place_segment(Segment2D(Point2D(147, -616), Point2D(117, -563)))
|
||||
# # place_segment(Segment2D(Point2D(147, -616), Point2D(97, -576)))
|
||||
# # place_segment(Segment2D(Point2D(147, -616), Point2D(71, -625)))
|
||||
# # place_segment(Segment2D(Point2D(147, -616), Point2D(115, -655)))
|
||||
# # place_segment(Segment2D(Point2D(147, -616), Point2D(162, -682)))
|
||||
# # 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(178, -575)))
|
||||
|
||||
place_segment(Segment2D(Point2D(0, 0), Point2D(50, 0)))
|
||||
place_segment(Segment2D(Point2D(0, 0), Point2D(50, 25)))
|
||||
place_segment(Segment2D(Point2D(0, 0), Point2D(50, 50)))
|
||||
place_segment(Segment2D(Point2D(0, 0), Point2D(25, 50)))
|
||||
place_segment(Segment2D(Point2D(0, 0), Point2D(0, 50)))
|
||||
place_segment(Segment2D(Point2D(0, 0), Point2D(-25, 50)))
|
||||
place_segment(Segment2D(Point2D(0, 0), Point2D(-50, 50)))
|
||||
place_segment(Segment2D(Point2D(0, 0), Point2D(-50, 25)))
|
||||
place_segment(Segment2D(Point2D(0, 0), Point2D(-50, 0)))
|
||||
place_segment(Segment2D(Point2D(0, 0), Point2D(-50, -25)))
|
||||
place_segment(Segment2D(Point2D(0, 0), Point2D(-50, -50)))
|
||||
place_segment(Segment2D(Point2D(0, 0), Point2D(-25, -50)))
|
||||
place_segment(Segment2D(Point2D(0, 0), Point2D(0, -50)))
|
||||
place_segment(Segment2D(Point2D(0, 0), Point2D(25, -50)))
|
||||
place_segment(Segment2D(Point2D(0, 0), Point2D(50, -50)))
|
||||
x = 200
|
||||
|
||||
# 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, 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(-25+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, 0)))
|
||||
# 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(-25+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(50+x, -50)))
|
||||
|
||||
# place_segment(Segment2D(Point2D(147, -616), Point2D(201, -595)))
|
||||
# place_segment(Segment2D(Point2D(147, -616), Point2D(233, -605)))
|
||||
|
||||
y = 105
|
||||
|
||||
# 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)
|
||||
|
||||
# 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)
|
||||
# Road([Point3D(526, 70, -415), Point3D(497, 76, -420), Point3D(483, 70, -381), Point3D(460, 71, -360), Point3D(430, 78, -383), Point3D(410, 71, -364), Point3D(381,
|
||||
|
||||
@@ -140,8 +140,9 @@ class Polyline:
|
||||
|
||||
# Get segments between arcs
|
||||
for i in range(2, self.length_polyline - 1):
|
||||
self.segments[i] = Segment2D(Point2D(self.acrs_intersections[i][0].x, self.acrs_intersections[i][0].y), Point2D(
|
||||
self.acrs_intersections[i-1][-1].x, self.acrs_intersections[i-1][-1].y))
|
||||
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))
|
||||
print(self.segments[i], i)
|
||||
|
||||
# Why -3?
|
||||
# For n points, there are n-1 segments.
|
||||
@@ -162,7 +163,8 @@ class Polyline:
|
||||
alpha_b = min(
|
||||
self.lengths[start_index] - self.alpha_radii[start_index], self.lengths[start_index + 1])
|
||||
current_radius = max(self.tangente[start_index] * self.alpha_radii[start_index],
|
||||
self.tangente[start_index + 1] * alpha_b) # Radius at initial segment
|
||||
# Radius at initial segment
|
||||
self.tangente[start_index + 1] * alpha_b)
|
||||
|
||||
if current_radius < minimum_radius:
|
||||
minimum_radius, minimum_index = current_radius, start_index
|
||||
@@ -180,7 +182,8 @@ class Polyline:
|
||||
self.lengths[end_index-2], self.lengths[end_index-1]-self.alpha_radii[end_index])
|
||||
|
||||
current_radius = max(self.tangente[end_index-1]*alpha_a, self.tangente[end_index]
|
||||
* self.alpha_radii[end_index]) # Radius at final segment
|
||||
# Radius at final segment
|
||||
* self.alpha_radii[end_index])
|
||||
|
||||
if current_radius < minimum_radius:
|
||||
minimum_radius, minimum_index = current_radius, end_index - 1
|
||||
|
||||
@@ -21,7 +21,7 @@ class Segment2D:
|
||||
def __repr__(self):
|
||||
return str(f"Segment2D(start: {self.start}, end: {self.end}, points: {self.points})")
|
||||
|
||||
def segment(self, start: Point2D = None, end: Point2D = None, overlap: LINE_OVERLAP = LINE_OVERLAP.NONE, _is_computing_thickness: int = 0) -> Union[List[Point2D], None]:
|
||||
def segment(self, start: Point2D = None, end: Point2D = None, overlap: LINE_OVERLAP = LINE_OVERLAP.NONE, _is_computing_thickness: int = -1) -> Union[List[Point2D], None]:
|
||||
"""Modified Bresenham draw (line) with optional overlap.
|
||||
|
||||
From: https://github.com/ArminJo/Arduino-BlueDisplay/blob/master/src/LocalGUI/ThickLine.hpp
|
||||
@@ -98,7 +98,7 @@ class Segment2D:
|
||||
self._add_points(
|
||||
start, _is_computing_thickness, LINE_OVERLAP.NONE)
|
||||
|
||||
if not _is_computing_thickness:
|
||||
if _is_computing_thickness < 0:
|
||||
return self.points
|
||||
return None
|
||||
|
||||
@@ -166,7 +166,7 @@ class Segment2D:
|
||||
start.y -= step_y
|
||||
end.y -= step_y
|
||||
error -= delta_2x
|
||||
error += delta_2x
|
||||
error += delta_2y
|
||||
|
||||
if not swap:
|
||||
self.segment(
|
||||
@@ -240,6 +240,16 @@ class Segment2D:
|
||||
|
||||
reel_distance = self.points_thick_by_line[0][0].distance(
|
||||
self.points_thick_by_line[-1][0])
|
||||
delta_correction = round(reel_distance - thickness)
|
||||
if delta_correction > 0:
|
||||
for i in range(delta_correction):
|
||||
if (-1) ** i == 1:
|
||||
index = -1
|
||||
else:
|
||||
index = 0
|
||||
print(i)
|
||||
del self.points_thick_by_line[index]
|
||||
del self.gaps[index]
|
||||
|
||||
return self.points_thick
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ from networks.geometry.Segment2D import Segment2D
|
||||
from networks.geometry.Segment3D import Segment3D
|
||||
from networks.geometry.Circle import Circle
|
||||
from utils.Enums import LINE_THICKNESS_MODE
|
||||
from gdpc import Block, Editor
|
||||
from gdpc import Block, Editor, geometry
|
||||
|
||||
|
||||
class Road:
|
||||
@@ -92,13 +92,13 @@ class Road:
|
||||
nearest = self.polyline.segments[i].gaps[k][m].nearest(
|
||||
Point3D.to_2d(self.polyline_total_line_output, removed_axis='y'), True)
|
||||
self.output_block.append(
|
||||
(Point3D.insert_3d([self.polyline.segments[i].gaps[k][m]], 'y', [self.polyline_total_line_output[nearest[0]].y])[0].coordinates, Block("white_concrete")))
|
||||
(Point3D.insert_3d([self.polyline.segments[i].gaps[k][m]], 'y', [self.polyline_total_line_output[nearest[0]].y])[0].coordinates, Block("black_concrete")))
|
||||
|
||||
for i in range(1, len(self.polyline.centers)-1):
|
||||
# Circle
|
||||
|
||||
circle, gaps = Circle(self.polyline.centers[i]).circle_thick_by_line(int(
|
||||
(self.polyline.radii[i]-self.width/2)), int((self.polyline.radii[i]+self.width/2)))
|
||||
(self.polyline.radii[i]-self.width/2))+1, int((self.polyline.radii[i]+self.width/2))+1)
|
||||
|
||||
# Better to do here than drawing circle arc inside big triangle!
|
||||
double_point_a = Point2D.from_arrays(Point2D.to_arrays(self.polyline.acrs_intersections[i][0]) + 5 * (Point2D.to_arrays(
|
||||
@@ -106,6 +106,17 @@ class Road:
|
||||
double_point_b = Point2D.from_arrays(Point2D.to_arrays(self.polyline.acrs_intersections[i][2]) + 5 * (Point2D.to_arrays(
|
||||
self.polyline.acrs_intersections[i][2]) - Point2D.to_arrays(self.polyline.centers[i])))
|
||||
|
||||
editor = Editor(buffering=True)
|
||||
editor.placeBlock(Point3D.insert_3d(
|
||||
[self.polyline.acrs_intersections[i][0]], 'y', [230])[0].coordinates, Block("purple_concrete"))
|
||||
editor.placeBlock(Point3D.insert_3d(
|
||||
[self.polyline.acrs_intersections[i][2]], 'y', [230])[0].coordinates, Block("pink_concrete"))
|
||||
|
||||
geometry.placeLine(editor, Point3D.insert_3d([double_point_a], 'y', [250])[
|
||||
0].coordinates, Point3D.insert_3d([self.polyline.centers[i]], 'y', [250])[0].coordinates, Block("blue_concrete"))
|
||||
geometry.placeLine(editor, Point3D.insert_3d([double_point_b], 'y', [250])[
|
||||
0].coordinates, Point3D.insert_3d([self.polyline.centers[i]], 'y', [250])[0].coordinates, Block("red_concrete"))
|
||||
|
||||
for j in range(len(circle)):
|
||||
for k in range(len(circle[j])):
|
||||
jj = j % 7
|
||||
@@ -176,7 +187,7 @@ class Road:
|
||||
self.segment_total_line_output[i].x, reference[self.segment_total_line_output[i].nearest(Point3D.to_2d(reference, 'y'), True)[0]].y, self.segment_total_line_output[i].y), Block("black_concrete")))
|
||||
|
||||
def place(self):
|
||||
editor = Editor(buffering=False)
|
||||
editor = Editor(buffering=True)
|
||||
for i in range(len(self.output_block)):
|
||||
editor.placeBlock(self.output_block[i][0],
|
||||
self.output_block[i][1])
|
||||
|
||||
Reference in New Issue
Block a user