Better offset
This commit is contained in:
24
main.py
24
main.py
@@ -27,20 +27,18 @@ 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]))))
|
||||
|
||||
for i in range(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=160)
|
||||
offset = curve.offset(curve_points, i)
|
||||
|
||||
curve_points = curve.curve(
|
||||
[(390, 150, 788), (368, 155, 803), (377, 160, 836)], resolution=5)
|
||||
offset = curve.offset(curve_points, 10)
|
||||
for coordinate in offset:
|
||||
editor.placeBlock(coordinate, Block("blue_concrete"))
|
||||
|
||||
for coordinate in offset:
|
||||
editor.placeBlock(coordinate, Block("blue_concrete"))
|
||||
offset = curve.offset(curve_points, -i)
|
||||
|
||||
curve_points = curve.curve(
|
||||
[(390, 150, 788), (368, 155, 803), (377, 160, 836)], resolution=5)
|
||||
offset = curve.offset(curve_points, -10)
|
||||
for coordinate in offset:
|
||||
editor.placeBlock(coordinate, Block("red_concrete"))
|
||||
|
||||
for coordinate in offset:
|
||||
editor.placeBlock(coordinate, Block("red_concrete"))
|
||||
|
||||
for coordinate in curve_points:
|
||||
editor.placeBlock(coordinate, Block("white_concrete"))
|
||||
for coordinate in curve_points:
|
||||
editor.placeBlock(coordinate, Block("white_concrete"))
|
||||
|
||||
@@ -80,10 +80,20 @@ def offset(curve, distance):
|
||||
curvature_values = curvature(curve)
|
||||
|
||||
# Offsetting
|
||||
offset_curve = [segment.parallel(
|
||||
(curve[i], curve[i+1]), distance) for i in range(len(curve) - 1)]
|
||||
offset_segments = [segment.parallel(
|
||||
(curve[i], curve[i+1]), distance, curvature_values[i]) for i in range(len(curve) - 1)]
|
||||
|
||||
return offset_curve
|
||||
# Combining segments
|
||||
combined_curve = []
|
||||
combined_curve.append(np.round(offset_segments[0][0]).tolist())
|
||||
for i in range(0, len(offset_segments)-1):
|
||||
combined_curve.append(segment.middle_point(
|
||||
offset_segments[i][1], offset_segments[i+1][0]))
|
||||
combined_curve.append(np.round(offset_segments[-1][1]).tolist())
|
||||
|
||||
return combined_curve
|
||||
|
||||
# for i in range(1, len(offset_curve)-1):
|
||||
# pass
|
||||
|
||||
# TODO : Curve Offset
|
||||
|
||||
@@ -49,26 +49,27 @@ def orthogonal(origin, point, distance, normal=np.array([0, 1, 0])):
|
||||
if np.array_equal(orthogonal, np.zeros((3,))):
|
||||
raise ValueError("The input vectors are not linearly independent.")
|
||||
|
||||
orthogonal = np.add(np.multiply(orthogonal, distance), origin)
|
||||
orthogonal = np.round(
|
||||
np.add(np.multiply(orthogonal, distance), origin)).astype(int)
|
||||
return orthogonal
|
||||
|
||||
|
||||
def discrete_segment(xyz1, xyz2, pixel_perfect=True):
|
||||
def discrete_segment(start_point, end_point, pixel_perfect=True):
|
||||
"""
|
||||
Calculate a line between two points in 3D space.
|
||||
|
||||
https://www.geeksforgeeks.org/bresenhams-algorithm-for-3-d-line-drawing/
|
||||
|
||||
Args:
|
||||
xyz1 (tuple): First coordinates.
|
||||
xyz2 (tuple): Second coordinates.
|
||||
start_point (tuple): (x, y, z) First coordinates.
|
||||
end_point (tuple): (x, y, z) Second coordinates.
|
||||
pixel_perfect (bool, optional): If true, remove unnecessary coordinates connecting to other coordinates side by side, leaving only a diagonal connection. Defaults to True.
|
||||
|
||||
Returns:
|
||||
list: List of coordinates.
|
||||
"""
|
||||
(x1, y1, z1) = xyz1
|
||||
(x2, y2, z2) = xyz2
|
||||
(x1, y1, z1) = start_point
|
||||
(x2, y2, z2) = end_point
|
||||
x1, y1, z1, x2, y2, z2 = (
|
||||
round(x1),
|
||||
round(y1),
|
||||
@@ -162,3 +163,10 @@ def discrete_segment(xyz1, xyz2, pixel_perfect=True):
|
||||
p1 += 2 * dy
|
||||
p2 += 2 * dx
|
||||
return points
|
||||
|
||||
|
||||
def middle_point(start_point, end_point):
|
||||
return (np.round((start_point[0] + end_point[0]) / 2.0).astype(int),
|
||||
np.round((start_point[1] + end_point[1]) / 2.0).astype(int),
|
||||
np.round((start_point[2] + end_point[2]) / 2.0).astype(int),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user