From 1c454947dcf2abe313e68fa3bcdbd831c69413bb Mon Sep 17 00:00:00 2001 From: Xeon0X Date: Thu, 25 Apr 2024 19:09:51 +0200 Subject: [PATCH] Add curve resolution from spacing distance --- main.py | 23 +++++++++++++++-------- networks/Curve.py | 12 ++++++++++++ 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/main.py b/main.py index c67b6d9..11a9d75 100644 --- a/main.py +++ b/main.py @@ -27,18 +27,25 @@ editor = Editor(buffering=True) # print(segment.orthogonal((0, 0, 0), (1, 0, 0), 10)) # print(curve.curvature(np.array(([0, 0, 0], [0, 1, 1], [1, 0, 1])))) + +coordinates = [(-854, 77, -210), (-770, 89, -207), (-736, 75, -184)] + +resolution = curve.resolution_from_spacing(coordinates, 10) + i = 10 -curve_points = curve.curve( - [(317, 90, 686), (291, 95, 686), (271, 100, 705), (250, 95, 715), (234, 90, 692), (220, 146, 607), (185, 158, 598), (146, 90, 596), (142, 70, 674)], resolution=40) -offset = curve.offset(curve_points, i) +curve_points = curve.curve(coordinates, resolution) -for coordinate in offset: - editor.placeBlock(coordinate, Block("blue_concrete")) +# offset = curve.offset(curve_points, i) -offset = curve.offset(curve_points, -i) +# for coordinate in offset: +# editor.placeBlock(coordinate, Block("blue_concrete")) -for coordinate in offset: - editor.placeBlock(coordinate, Block("red_concrete")) +# offset = curve.offset(curve_points, -i) + +# for coordinate in offset: +# editor.placeBlock(coordinate, Block("red_concrete")) for coordinate in curve_points: editor.placeBlock(coordinate, Block("white_concrete")) + +### diff --git a/networks/Curve.py b/networks/Curve.py index fd04968..d37002e 100644 --- a/networks/Curve.py +++ b/networks/Curve.py @@ -1,6 +1,7 @@ import numpy as np import networks.Segment as segment from scipy import interpolate +from math import sqrt def curve(target_points, resolution=40): @@ -92,3 +93,14 @@ def offset(curve, distance): combined_curve.append(np.round(offset_segments[-1][1]).tolist()) return combined_curve + + +def resolution_from_spacing(target_points, spacing_distance): + length = 0 + for i in range(len(target_points) - 1): + length += sqrt( + ((target_points[i][0] - target_points[i + 1][0]) ** 2) + + ((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)