From 80540d0852f230a8fd8a5f05cf82894ee978afa2 Mon Sep 17 00:00:00 2001 From: jaseg Date: Fri, 2 Aug 2024 16:06:34 +0200 Subject: [PATCH] design improvements --- secondary_mesh_planning.py | 68 ++++++++++++++++++++++++-------------- 1 file changed, 44 insertions(+), 24 deletions(-) diff --git a/secondary_mesh_planning.py b/secondary_mesh_planning.py index 09e9e77..de9c83b 100644 --- a/secondary_mesh_planning.py +++ b/secondary_mesh_planning.py @@ -82,21 +82,37 @@ def cli(out_svg, mesh_thickness, offset, mesh_space, mesh_width, start, initial_ tags = [] dim_tags = [] + hls_svg = lambda h, s, l: '#'+''.join(f'{round(c*255):02x}' for c in colorsys.hls_to_rgb(h/360, l/100, s/100)) + + current_color = lambda s, l: hls_svg(0, l, s) + next_color = lambda s, l: hls_svg(240, l, s) + + # https://stackoverflow.com/questions/13069446/simple-fill-pattern-in-svg-diagonal-hatching + tags.append(Tag('pattern', [Tag('path', stroke=current_color(40, 70), stroke_width=1, + d='M -1,1 l 2,-2 M 0,4 l 4,-4 M 3,5 l2,-2')], + id='hatch_current', patternUnits='userSpaceOnUse', width='4', height='4', patternTransform='rotate(-45) scale(0.2)')) + tags.append(Tag('pattern', [Tag('path', stroke=next_color(40, 70), stroke_width=1, + d='M -1,1 l 2,-2 M 0,4 l 4,-4 M 3,5 l2,-2')], + id='hatch_next', patternUnits='userSpaceOnUse', width='4', height='4', patternTransform='scale(0.2)')) + + current_fill, next_fill = 'url(#hatch_current)', 'url(#hatch_next)' + + circle = lambda pt, r, c, w=0.2, op=1.0: Tag('circle', stroke=c, fill='none', stroke_width=w, cx=pt[0], cy=pt[1], r=r, stroke_opacity=op) current_radius = initial_radius - def ring(pt, c): + def ring(pt, c, fill): nonlocal current_radius c_line = c(40, 70) - c_area = c(40, 70) + c_area = fill c_bar = c(40, 40) r1 = current_radius r2 = math.hypot(mesh_width/2, r1 + mesh_thickness) - tags.append(circle(pt, (r1+r2)/2, c_area, r2-r1, 0.3)) + tags.append(circle(pt, (r1+r2)/2, c_area, r2-r1, 0.5)) tags.append(circle(pt, r1, c_line)) tags.append(circle(pt, r2, c_line)) @@ -109,8 +125,8 @@ def cli(out_svg, mesh_thickness, offset, mesh_space, mesh_width, start, initial_ current_radius = r2 def dimension(p1, p2, h=5, line_offset=1, arrow_offset=.5, inner_arrow_min=5, arrow_head_size=1, arrow_length=3, - connecting_line_offset=1, color='black', line_width=0.2, text_offset=3, text_offset_max=15, text_color=None, text_format='{:.2f} mm', - font_size=2): + connecting_line_offset=1, color='black', line_width=0.2, text_offset=3, text_offset_max=15, + text_color=None, text_format='{:.2f} mm', font_size=2, offset_1=0, offset_2 = 0): if text_color is None: text_color = color @@ -124,22 +140,26 @@ def cli(out_svg, mesh_thickness, offset, mesh_space, mesh_width, start, initial_ if l > inner_arrow_min: xa1, ya1 = x1 + ax*arrow_offset, y1 + ay*arrow_offset xa2, ya2 = x2 - ax*arrow_offset, y2 - ay*arrow_offset + cl_off = 2*arrow_offset + arrow_length else: xa2, ya2 = x1 - ax*arrow_offset, y1 - ay*arrow_offset xa1, ya1 = x2 + ax*arrow_offset, y2 + ay*arrow_offset + cl_off = 2*arrow_offset angle = math.degrees(math.atan2(dy, dx)) c_off = h - connecting_line_offset + print(cl_off, l/2) + cl_off = min(l/2, cl_off) yield Tag('path', fill='none', stroke=color, stroke_width=line_width, d=f''' M {x1-nx*line_width/2},{y1-ny*line_width/2} l {nx*line_width},{ny*line_width} - M {x1+nx*line_offset},{y1+ny*line_offset} l {nx*h},{ny*h} + M {x1+nx*(line_offset + offset_1)},{y1+ny*(line_offset+offset_1)} l {nx*(h-offset_1)},{ny*(h-offset_1)} M {x2-nx*line_width/2},{y2-ny*line_width/2} l {nx*line_width},{ny*line_width} - M {x2+nx*line_offset},{y2+ny*line_offset} l {nx*h},{ny*h} + M {x2+nx*(line_offset+offset_2)},{y2+ny*(line_offset+offset_2)} l {nx*(h-offset_2)},{ny*(h-offset_2)} - M {x1+nx*c_off + ax*arrow_offset},{y1+ny*c_off+ay*arrow_offset} - l {ax*(l-2*arrow_offset)},{ay*(l-2*arrow_offset)} + M {x1+nx*c_off + ax*cl_off},{y1+ny*c_off+ay*cl_off} + l {ax*(l-2*cl_off)},{ay*(l-2*cl_off)} ''') xa1, ya1 = xa1 + nx*c_off, ya1 + ny*c_off @@ -181,27 +201,23 @@ def cli(out_svg, mesh_thickness, offset, mesh_space, mesh_width, start, initial_ stroke_linejoin='round', fill=text_color) - crosshairs = lambda pt, s=3, color='black': Tag('path', fill='none', stroke_width=0.4, stroke=color, + crosshairs = lambda pt, s=2, color='black', xf='': Tag('path', fill='none', stroke_width=0.2, stroke=color, transform=xf, d=f'M {pt[0]-s},{pt[1]} h {2*s} m {-s},{s} v {-2*s}') current_point = (0, 0) next_point = (offset, 0) - hls_svg = lambda h, s, l: '#'+''.join(f'{round(c*255):02x}' for c in colorsys.hls_to_rgb(h/360, l/100, s/100)) - print(hls_svg(0, 50, 50)) - current_color = lambda s, l: hls_svg(0, l, s) - next_color = lambda s, l: hls_svg(240, l, s) - tags.append(crosshairs(current_point, color=current_color(40, 30))) - tags.append(crosshairs(next_point, color=next_color(40, 30))) + tags.append(crosshairs(next_point, color=next_color(40, 30), xf=f'rotate(45,{next_point[0]},{next_point[1]})')) if start == 'offset': current_point, next_point = next_point, current_point current_color, next_color = next_color, current_color + current_fill, next_fill = next_fill, current_fill - dim_tags += dimension(current_point, next_point, h=5) - dim_tags += dimension(current_point, (current_point[0]-initial_radius, current_point[1]), h=5) - dim_tags += dimension((current_point[0]+initial_radius, current_point[1]), next_point, h=5) + dim_tags += dimension(current_point, next_point, h=5, offset_1=2) + dim_tags += dimension(current_point, (current_point[0]-initial_radius, current_point[1]), h=5, offset_1 = 2) + dim_tags += dimension((current_point[0]+initial_radius, current_point[1]), next_point, h=10, offset_1=mesh_width/2) #if (r := offset - mesh_space - initial_radius) > 0: # ring(next_point, next_color) @@ -210,26 +226,30 @@ def cli(out_svg, mesh_thickness, offset, mesh_space, mesh_width, start, initial_ print(f'Radius at step {i}: {current_radius:.2f} mm') old_radius = current_radius - ring(current_point, current_color) + ring(current_point, current_color, current_fill) sign = -1 if current_point[0] - next_point[0] < 0 else 1 px, py = current_point - dim_tags += dimension((px + sign*current_radius, 0), (px + sign*old_radius, 0), h=10) + dim_tags += dimension((px + sign*current_radius, 0), (px + sign*old_radius, 0), h=10, offset_2=mesh_width/2) if i > 0: - dim_tags += dimension((px + sign*current_radius, 0), (px + sign*(current_radius+mesh_space), 0), h=10 + i*3) + dim_tags += dimension((px + sign*current_radius, 0), (px + sign*(current_radius+mesh_space), 0), h=10 + i*3, + offset_2=mesh_width/2) if i < 2: - dim_tags += dimension((px + sign*current_radius, 0), (px - sign*current_radius, 0), h=current_radius + 5) + dim_tags += dimension((px + sign*current_radius, 0), (px - sign*current_radius, 0), h=current_radius + 5, + offset_2=mesh_width/2) old_radius = current_radius current_radius += mesh_space + offset current_point, next_point = next_point, current_point current_color, next_color = next_color, current_color + current_fill, next_fill = next_fill, current_fill px, py = current_point if i > 0: dim_tags += dimension((px - sign*(old_radius-offset), 0), (px - sign*(current_radius-2*offset), 0), h=10) - dim_tags += dimension((px - sign*current_radius, 0), (px - sign*(current_radius-2*offset), 0), h=10) + dim_tags += dimension((px - sign*current_radius, 0), (px - sign*(current_radius-2*offset), 0), h=10, + offset_1=mesh_width/2) r_max = current_radius + offset