First prototype of roads intersecitons

This commit is contained in:
2024-05-28 00:51:29 +02:00
parent ba78bb4537
commit e879e9c034
4 changed files with 106 additions and 9 deletions

View File

@@ -1,5 +1,6 @@
from math import sqrt, cos, pi, sin
import numpy as np
from networks.geometry.segment_tools import discrete_segment, middle_point
def circle(center, radius):
@@ -51,7 +52,7 @@ def is_in_triangle(point, xy0, xy1, xy2):
def distance(xy1, xy2): # TODO : Can be better.
return sqrt((xy2[0] - xy1[0]) ** 2 + (xy2[1] - xy1[1]) ** 2)
return sqrt((xy2[0] - xy1[0]) ** 2 + (xy2[-1] - xy1[-1]) ** 2)
def get_angle(xy0, xy1, xy2):
@@ -210,11 +211,17 @@ def segments_intersection(line0, line1, full_line=True):
<= y
<= max(line1[0][-1], line1[1][-1])
):
return x, y
if len(line0[0]) > 2:
return middle_point(nearest(discrete_segment(line1[0], line1[1], pixel_perfect=True), (x, y)), nearest(discrete_segment(line0[0], line0[1], pixel_perfect=True), (x, y)))
else:
return x, y
else:
return None
else:
return x, y
if len(line0[0]) > 2:
return middle_point(nearest(discrete_segment(line1[0], line1[1], pixel_perfect=True), (x, y)), nearest(discrete_segment(line0[0], line0[1], pixel_perfect=True), (x, y)))
else:
return x, y
def circle_segment_intersection(

View File

@@ -2,6 +2,7 @@ class Road:
def __init__(self, coordinates, road_configuration):
self.coordinates = coordinates # List of tuples (x1, y1, z1) in order
self.road_configuration = road_configuration # 'road', 'highway'
self.width = 10 # TODO
def place_roads(self):
pass

View File

@@ -1,3 +1,30 @@
from networks.geometry.segment_tools import parallel, orthogonal
from networks.geometry.point_tools import sort_by_clockwise, segments_intersection
from networks.roads import Road
class Intersection:
def __init__(self, Roads):
def __init__(self, center, coordinates, Roads):
self.center = center
self.coordinates = coordinates
self.Roads = Roads
self.parallel_delimitations = []
self.orthogonal_delimitations = []
self.intersections = []
def compute_curved_corner(self):
# Necessary to test nearby intersection
self.coordinates = sort_by_clockwise(self.coordinates)
for i, coordinate in enumerate(self.coordinates):
right_side, left_side = parallel((coordinate, self.center), self.Roads[i].width), parallel(
(coordinate, self.center), -self.Roads[i].width)
self.parallel_delimitations.append((right_side, left_side))
self.orthogonal_delimitations.append(
((right_side[0], left_side[0]), (right_side[-1], left_side[-1])))
for j in range(len(self.Roads)):
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)