First implementation of curve surface failed (not enough precision)

This commit is contained in:
2024-04-26 12:38:15 +02:00
parent bdde8f54b1
commit 323111f2f6
4 changed files with 53 additions and 34 deletions

View File

@@ -77,12 +77,14 @@ def curvature(curve):
return normal
def offset(curve, distance):
curvature_values = curvature(curve)
def offset(curve, distance, normals):
if len(normals) != len(curve):
raise ValueError(
'Number of normals and number of points in the curve do not match')
# Offsetting
offset_segments = [segment.parallel(
(curve[i], curve[i+1]), distance, curvature_values[i]) for i in range(len(curve) - 1)]
(curve[i], curve[i+1]), distance, normals[i]) for i in range(len(curve) - 1)]
# Combining segments
combined_curve = []
@@ -95,7 +97,7 @@ def offset(curve, distance):
return combined_curve
def resolution_from_spacing(target_points, spacing_distance):
def resolution_distance(target_points, spacing_distance):
length = 0
for i in range(len(target_points) - 1):
length += sqrt(
@@ -103,7 +105,7 @@ def resolution_from_spacing(target_points, spacing_distance):
+ ((target_points[i][1] - target_points[i + 1][1]) ** 2)
+ ((target_points[i][2] - target_points[i + 1][2]) ** 2)
)
return round(length / spacing_distance)
return round(length / spacing_distance), length
def simplify_segments(points, epsilon):

30
networks/CurveSurface.py Normal file
View File

@@ -0,0 +1,30 @@
import networks.Curve as curve
import networks.Segment as segment
import numpy as np
class CurveSurface:
def __init__(self, points, reshape=True, spacing_distance=10):
self.points = np.array(points)
if reshape:
self.resolution, self.length = curve.resolution_distance(
self.points, spacing_distance=spacing_distance)
self.curve = curve.curve(self.points, self.resolution)
else: # Point can also be given already in curved form
self.curve = self.points
def compute_curvature(self):
self.curvature = curve.curvature(self.curve)
def compute_surface(self, width, normals, resolution):
self.offset_points = [None] * (width * resolution)
self.surface = []
for line_range in range(width * resolution):
self.offset_points[line_range] = curve.offset(
self.curve, line_range/resolution, normals)
for i in range(len(self.offset_points[line_range])-1):
self.surface.extend(segment.discrete_segment(
self.offset_points[line_range][i], self.offset_points[line_range][i+1], pixel_perfect=False))
print(self.surface)

3
networks/roads/Lane.py Normal file
View File

@@ -0,0 +1,3 @@
class Lane:
def __init__(self, coordinates, lane_type):
pass