Fix lenght bug
This commit is contained in:
23
main.py
23
main.py
@@ -308,10 +308,13 @@ random_points = [Point2D(random.randint(min_val, max_val), random.randint(
|
|||||||
|
|
||||||
random_points = random_points[0].optimized_path(random_points)
|
random_points = random_points[0].optimized_path(random_points)
|
||||||
|
|
||||||
|
print(random_points)
|
||||||
|
|
||||||
|
# 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)]
|
||||||
|
|
||||||
p = Polyline(random_points)
|
p = Polyline(random_points)
|
||||||
|
|
||||||
# Point2D(-1156, 378), Point2D(-1220, 359), Point2D(-1265, 290)
|
|
||||||
# print(p.alpha_radii)
|
|
||||||
|
|
||||||
radius = p.get_radii()
|
radius = p.get_radii()
|
||||||
center = p.get_centers()
|
center = p.get_centers()
|
||||||
@@ -388,9 +391,9 @@ for j in range(len(s1.points_thick)-1):
|
|||||||
draw.point((s1.points_thick[j].x+w,
|
draw.point((s1.points_thick[j].x+w,
|
||||||
w-s1.points_thick[j].y), fill='grey')
|
w-s1.points_thick[j].y), fill='grey')
|
||||||
|
|
||||||
for i in range(0, len(p.arcs)):
|
# for i in range(0, len(p.arcs)):
|
||||||
for j in range(len(p.arcs[i])):
|
# for j in range(len(p.arcs[i])):
|
||||||
draw.point((p.arcs[i][j].x+w, w-p.arcs[i][j].y), fill='white')
|
# draw.point((p.arcs[i][j].x+w, w-p.arcs[i][j].y), fill='green')
|
||||||
|
|
||||||
|
|
||||||
for i in range(1, len(p.segments)-1):
|
for i in range(1, len(p.segments)-1):
|
||||||
@@ -398,6 +401,12 @@ for i in range(1, len(p.segments)-1):
|
|||||||
draw.point((p.segments[i].points_thick[j].x+w,
|
draw.point((p.segments[i].points_thick[j].x+w,
|
||||||
w-p.segments[i].points_thick[j].y), fill='white')
|
w-p.segments[i].points_thick[j].y), fill='white')
|
||||||
|
|
||||||
|
|
||||||
|
def get_color(i):
|
||||||
|
color = (50+round(i), 50+round(i/5), 50+round(i/3))
|
||||||
|
return color
|
||||||
|
|
||||||
|
|
||||||
for i in range(1, len(p.centers)-1):
|
for i in range(1, len(p.centers)-1):
|
||||||
draw.point((p.centers[i].x+w, w-p.centers[i].y), fill='red')
|
draw.point((p.centers[i].x+w, w-p.centers[i].y), fill='red')
|
||||||
draw.point((p.acrs_intersections[i][0].x+w,
|
draw.point((p.acrs_intersections[i][0].x+w,
|
||||||
@@ -407,6 +416,10 @@ for i in range(1, len(p.centers)-1):
|
|||||||
draw.point((p.acrs_intersections[i][2].x+w,
|
draw.point((p.acrs_intersections[i][2].x+w,
|
||||||
w-p.acrs_intersections[i][2].y), fill='blue')
|
w-p.acrs_intersections[i][2].y), fill='blue')
|
||||||
|
|
||||||
|
for i in range(len(p.total_line_output)):
|
||||||
|
draw.point((p.total_line_output[i].x+w,
|
||||||
|
w-p.total_line_output[i].y), fill=get_color(i))
|
||||||
|
|
||||||
image.save('output_image.png')
|
image.save('output_image.png')
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -7,8 +7,6 @@ from networks.geometry.Circle import Circle
|
|||||||
from networks.geometry.Point2D import Point2D
|
from networks.geometry.Point2D import Point2D
|
||||||
from networks.geometry.Segment2D import Segment2D
|
from networks.geometry.Segment2D import Segment2D
|
||||||
|
|
||||||
# from Enums import LINE_THICKNESS_MODE, LINE_OVERLAP
|
|
||||||
|
|
||||||
|
|
||||||
class Polyline:
|
class Polyline:
|
||||||
def __init__(self, points: List[Point2D]):
|
def __init__(self, points: List[Point2D]):
|
||||||
@@ -46,8 +44,8 @@ class Polyline:
|
|||||||
self.centers = [None] * self.length_polyline # c, list of points
|
self.centers = [None] * self.length_polyline # c, list of points
|
||||||
# list of tuple of points (first intersection, corresponding corner, last intersection)
|
# list of tuple of points (first intersection, corresponding corner, last intersection)
|
||||||
self.acrs_intersections = [None] * self.length_polyline
|
self.acrs_intersections = [None] * self.length_polyline
|
||||||
self.arcs = [[]] * self.length_polyline # list of points
|
self.arcs = [[] for _ in range(self.length_polyline)] # list of points
|
||||||
self.bisectors = [None] * self.length_polyline
|
# self.bisectors = [None] * self.length_polyline
|
||||||
|
|
||||||
# For n points, there is n-1 segments. Last element should stays None.
|
# For n points, there is n-1 segments. Last element should stays None.
|
||||||
self.segments = [None] * \
|
self.segments = [None] * \
|
||||||
@@ -64,6 +62,13 @@ class Polyline:
|
|||||||
self.get_arcs()
|
self.get_arcs()
|
||||||
self.get_segments()
|
self.get_segments()
|
||||||
|
|
||||||
|
self.total_line_output = []
|
||||||
|
# for i in range(1, self.length_polyline-1):
|
||||||
|
# self.total_line_output.extend(self.segments[i].segment())
|
||||||
|
# self.total_line_output.extend(self.arcs[i])
|
||||||
|
self.total_line_output.extend(self.segments[1].segment())
|
||||||
|
self.total_line_output.extend(self.arcs[2])
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return str(self.alpha_radii)
|
return str(self.alpha_radii)
|
||||||
|
|
||||||
@@ -101,16 +106,19 @@ class Polyline:
|
|||||||
|
|
||||||
def get_arcs(self) -> List[Point2D]:
|
def get_arcs(self) -> List[Point2D]:
|
||||||
for i in range(1, self.length_polyline-1):
|
for i in range(1, self.length_polyline-1):
|
||||||
circle = Circle(self.centers[i])
|
points = Circle(self.centers[i]).circle(self.radii[i])
|
||||||
circle.circle(self.radii[i])
|
|
||||||
for j in range(len(circle.points)):
|
|
||||||
if circle.points[j].is_in_triangle(self.acrs_intersections[i][0], self.acrs_intersections[i][1], self.acrs_intersections[i][2]):
|
|
||||||
self.arcs[i].append(circle.points[j])
|
|
||||||
self.bisectors[i] = Point2D.to_arrays(
|
|
||||||
self.centers[i]) + (self.unit_vectors[i-1] - self.points_array[i])
|
|
||||||
|
|
||||||
(self.unit_vectors[i]+self.unit_vectors[i-1]) / \
|
# Better to do here than drawing circle arc inside big triangle!
|
||||||
np.linalg.norm(self.unit_vectors[i]-self.unit_vectors[i-1])
|
double_point_a = Point2D.from_arrays(Point2D.to_arrays(self.acrs_intersections[i][0]) + 5 * (Point2D.to_arrays(
|
||||||
|
self.acrs_intersections[i][0]) - Point2D.to_arrays(self.centers[i])))
|
||||||
|
double_point_b = Point2D.from_arrays(Point2D.to_arrays(self.acrs_intersections[i][2]) + 5 * (Point2D.to_arrays(
|
||||||
|
self.acrs_intersections[i][2]) - Point2D.to_arrays(self.centers[i])))
|
||||||
|
input("---")
|
||||||
|
for j in range(len(points)):
|
||||||
|
print(points[j], i, j, len(points))
|
||||||
|
print(len(self.arcs[i]), len(self.arcs[i-1]))
|
||||||
|
if points[j].is_in_triangle(double_point_a, self.centers[i], double_point_b):
|
||||||
|
self.arcs[i].append(points[j])
|
||||||
return self.arcs
|
return self.arcs
|
||||||
|
|
||||||
def get_segments(self) -> List[Segment2D]:
|
def get_segments(self) -> List[Segment2D]:
|
||||||
@@ -134,8 +142,8 @@ class Polyline:
|
|||||||
|
|
||||||
# Get last segment. Index is -2 because last index -1 should be None due to the same list lenght.
|
# Get last segment. Index is -2 because last index -1 should be None due to the same list lenght.
|
||||||
# For n points, there are n-1 segments.
|
# For n points, there are n-1 segments.
|
||||||
self.segments[-2] = Segment2D(self.acrs_intersections[-2][2], Point2D.from_arrays(
|
# self.segments[-2] = Segment2D(self.acrs_intersections[-2][2], Point2D.from_arrays(
|
||||||
self.points_array[-1]))
|
# self.points_array[-1]))
|
||||||
|
|
||||||
return self.segments
|
return self.segments
|
||||||
|
|
||||||
|
|||||||
@@ -20,21 +20,15 @@ class Road:
|
|||||||
self.width = width
|
self.width = width
|
||||||
|
|
||||||
self.polyline = Polyline(Point3D.to_2d(coordinates, 'y'))
|
self.polyline = Polyline(Point3D.to_2d(coordinates, 'y'))
|
||||||
self.surface()
|
self._surface()
|
||||||
|
|
||||||
# for i in range(1, len(self.polyline.segments)-1):
|
def _surface(self):
|
||||||
# print(self._y_interpolation(self.polyline.segments[i].segment_thick(
|
|
||||||
# self.width, LINE_THICKNESS_MODE.MIDDLE)))
|
|
||||||
# self._y_interpolation(self.polyline.segments[i].segment())
|
|
||||||
|
|
||||||
def surface(self):
|
|
||||||
# Segments
|
# Segments
|
||||||
for i in range(1, len(self.polyline.segments)-1):
|
for i in range(1, len(self.polyline.segments)-1):
|
||||||
print()
|
|
||||||
if len(self.polyline.segments[i].segment()) > 1:
|
if len(self.polyline.segments[i].segment()) > 1:
|
||||||
for j in range(len(self.polyline.segments[i].segment_thick(self.width, LINE_THICKNESS_MODE.MIDDLE))):
|
for j in range(len(self.polyline.segments[i].segment_thick(self.width, LINE_THICKNESS_MODE.MIDDLE))):
|
||||||
self.output_block.append(
|
self.output_block.append(
|
||||||
(Point3D.insert_3d([self.polyline.segments[i].points_thick[j]], 'y', [170])[0].coordinates, Block("stone")))
|
(Point3D.insert_3d([self.polyline.segments[i].points_thick[j]], 'y', [180])[0].coordinates, Block("stone")))
|
||||||
|
|
||||||
for i in range(1, len(self.polyline.centers)-1):
|
for i in range(1, len(self.polyline.centers)-1):
|
||||||
# Circle
|
# Circle
|
||||||
@@ -53,24 +47,10 @@ class Road:
|
|||||||
if circle.points_thick[j].is_in_triangle(double_point_a, self.polyline.centers[i], double_point_b):
|
if circle.points_thick[j].is_in_triangle(double_point_a, self.polyline.centers[i], double_point_b):
|
||||||
self.output_block.append(
|
self.output_block.append(
|
||||||
(Point3D.insert_3d([circle.points_thick[j]], 'y', [
|
(Point3D.insert_3d([circle.points_thick[j]], 'y', [
|
||||||
170+i])[0].coordinates, Block("white_concrete")))
|
180+i])[0].coordinates, Block("black_concrete")))
|
||||||
|
|
||||||
# v = Point2D.to_arrays(
|
def _projection(self):
|
||||||
# self.polyline.centers[i]) - self.polyline.bisectors[i]
|
pass
|
||||||
|
|
||||||
# print(self.polyline.centers[i], Point2D.from_arrays(v).round())
|
|
||||||
# # s = Segment2D(
|
|
||||||
# # self.polyline.centers[i], Point2D.from_arrays(v).round())
|
|
||||||
# # s.segment()
|
|
||||||
# arc = Point2D.to_arrays(self.polyline.acrs_intersections[i][0])
|
|
||||||
# s = Segment2D(
|
|
||||||
# self.polyline.centers[i], Point2D.from_arrays(arc))
|
|
||||||
# s.segment()
|
|
||||||
|
|
||||||
# for j in range(len(s.points)):
|
|
||||||
# self.output_block.append(
|
|
||||||
# (Point3D.insert_3d([s.points[j]], 'y', [
|
|
||||||
# 162])[0].coordinates, Block("purple_concrete")))
|
|
||||||
|
|
||||||
def place(self):
|
def place(self):
|
||||||
editor = Editor(buffering=True)
|
editor = Editor(buffering=True)
|
||||||
|
|||||||
BIN
output_image.png
BIN
output_image.png
Binary file not shown.
|
Before Width: | Height: | Size: 1.9 KiB After Width: | Height: | Size: 2.0 KiB |
Reference in New Issue
Block a user