Fix lenght bug
This commit is contained in:
@@ -7,8 +7,6 @@ from networks.geometry.Circle import Circle
|
||||
from networks.geometry.Point2D import Point2D
|
||||
from networks.geometry.Segment2D import Segment2D
|
||||
|
||||
# from Enums import LINE_THICKNESS_MODE, LINE_OVERLAP
|
||||
|
||||
|
||||
class Polyline:
|
||||
def __init__(self, points: List[Point2D]):
|
||||
@@ -46,8 +44,8 @@ class Polyline:
|
||||
self.centers = [None] * self.length_polyline # c, list of points
|
||||
# list of tuple of points (first intersection, corresponding corner, last intersection)
|
||||
self.acrs_intersections = [None] * self.length_polyline
|
||||
self.arcs = [[]] * self.length_polyline # list of points
|
||||
self.bisectors = [None] * self.length_polyline
|
||||
self.arcs = [[] for _ in range(self.length_polyline)] # list of points
|
||||
# self.bisectors = [None] * self.length_polyline
|
||||
|
||||
# For n points, there is n-1 segments. Last element should stays None.
|
||||
self.segments = [None] * \
|
||||
@@ -64,6 +62,13 @@ class Polyline:
|
||||
self.get_arcs()
|
||||
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):
|
||||
return str(self.alpha_radii)
|
||||
|
||||
@@ -101,16 +106,19 @@ class Polyline:
|
||||
|
||||
def get_arcs(self) -> List[Point2D]:
|
||||
for i in range(1, self.length_polyline-1):
|
||||
circle = Circle(self.centers[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])
|
||||
points = Circle(self.centers[i]).circle(self.radii[i])
|
||||
|
||||
(self.unit_vectors[i]+self.unit_vectors[i-1]) / \
|
||||
np.linalg.norm(self.unit_vectors[i]-self.unit_vectors[i-1])
|
||||
# Better to do here than drawing circle arc inside big triangle!
|
||||
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
|
||||
|
||||
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.
|
||||
# For n points, there are n-1 segments.
|
||||
self.segments[-2] = Segment2D(self.acrs_intersections[-2][2], Point2D.from_arrays(
|
||||
self.points_array[-1]))
|
||||
# self.segments[-2] = Segment2D(self.acrs_intersections[-2][2], Point2D.from_arrays(
|
||||
# self.points_array[-1]))
|
||||
|
||||
return self.segments
|
||||
|
||||
|
||||
@@ -20,21 +20,15 @@ class Road:
|
||||
self.width = width
|
||||
|
||||
self.polyline = Polyline(Point3D.to_2d(coordinates, 'y'))
|
||||
self.surface()
|
||||
self._surface()
|
||||
|
||||
# for i in range(1, len(self.polyline.segments)-1):
|
||||
# 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):
|
||||
def _surface(self):
|
||||
# Segments
|
||||
for i in range(1, len(self.polyline.segments)-1):
|
||||
print()
|
||||
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))):
|
||||
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):
|
||||
# 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):
|
||||
self.output_block.append(
|
||||
(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(
|
||||
# self.polyline.centers[i]) - self.polyline.bisectors[i]
|
||||
|
||||
# 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 _projection(self):
|
||||
pass
|
||||
|
||||
def place(self):
|
||||
editor = Editor(buffering=True)
|
||||
|
||||
Reference in New Issue
Block a user