diff --git a/scripts/build_candidate_comparison.py b/scripts/build_candidate_comparison.py index 9b80746..8888377 100644 --- a/scripts/build_candidate_comparison.py +++ b/scripts/build_candidate_comparison.py @@ -14,6 +14,7 @@ import argparse import csv import sys +import textwrap from collections import defaultdict from pathlib import Path @@ -65,14 +66,14 @@ base = summary[args.base] cols = min(len(names), 4) rows = (len(names) + cols - 1) // cols - fig, axes = plt.subplots(rows, cols, figsize=(4.2 * cols, 4.9 * rows), squeeze=False) + fig, axes = plt.subplots(rows, cols, figsize=(4.2 * cols, 6.0 * rows), squeeze=False) image = None for ax, name in zip(axes.ravel(), names, strict=False): roi = load_sim_roi(OUTPUT_BASE / name / "s0" / "luminance.npy") image = ax.imshow(display_map(roi), cmap="hot", vmin=VMIN, vmax=VMAX) m = summary[name] ax.set_title( - f"{name}: {m['note']}\n" + f"{name}\n{textwrap.fill(str(m['note']), 24)}\n" f"構造CoV {m['structure_cov']:.4f}(現行比 {m['structure_cov'] / base['structure_cov']:.2f})\n" # noqa: E501 f"min 全体 {m['min_fullimage']:.3f} / 輪帯 {m['min_ring']:.3f}\n" f"明るさ 現行比 {m['mean'] / base['mean']:.2f}(LED {m['n_led']} 個)", diff --git a/scripts/generate_cube_housing.py b/scripts/generate_cube_housing.py index fa6f156..377e1ff 100644 --- a/scripts/generate_cube_housing.py +++ b/scripts/generate_cube_housing.py @@ -468,6 +468,79 @@ return mesh +def _rounded_polytope( + planes_vertex: list[tuple[np.ndarray, float]], sphere: np.ndarray +) -> trimesh.Trimesh: + """各頂点に,その頂点で交わる 3 面に接する球を置き,その凸包を返す. + + 球の半径を頂点ごとに変えても各面は元の平面上に残る(全ての球が同じ平面に接する)ため, + 稜ごとに丸める半径が違う凸多面体を作れる.planes_vertex は (球の中心, 半径) の並び. + """ + points = np.vstack([center + radius * sphere for center, radius in planes_vertex]) + return trimesh.convex.convex_hull(points) + + +def build_rounded_sloped_box_housing( + half_x: float, + y_min: float, + y_top: float, + slope: float, + depth: float, + thickness: float, + board_half_x: float, + board_half_y: float, + rim_inset: float, + rim_z: float, + fillet: float, + top_edge_fillet: float, + sphere_subdivisions: int = 4, +) -> trimesh.Trimesh: + """build_sloped_box_housing の内側の稜と角を丸めた版(外側は fillet + thickness で丸まる). + + 天井と +Y 側の傾いた壁の稜(評価板の上の縁に近い)は top_edge_fillet で丸め, + 他は fillet で丸める.天井の平らな部分が評価板の縁より狭くならないよう + top_edge_fillet は小さくする.内面は凸多面体なので,頂点ごとに 3 面に接する球を置いて + 凸包を取り(_rounded_polytope),外面との差から評価板の開口を抜く. + + Raises: + ValueError: 丸める半径が正でない,または天井の平らな部分が評価板の縁より狭い場合. + """ + if fillet <= 0.0 or top_edge_fillet <= 0.0: + raise ValueError("fillet と top_edge_fillet は正の値にしてください") + hx_in = board_half_x - rim_inset + hy_in = board_half_y - rim_inset + norm = float(np.hypot(1.0, slope)) + # 天井と傾いた壁のなす角(内側)の半分の tan.稜から接点までの距離 = r / tan(角/2) + half_angle_tan = np.tan((np.pi / 2 + np.arctan(slope)) / 2) + if y_top - top_edge_fillet / half_angle_tan < board_half_y: + raise ValueError("天井の +Y 側の平らな部分が評価板の縁より狭くなります." + "top_edge_fillet を小さくしてください") + if half_x - fillet < board_half_x or -y_min - fillet < board_half_y: + raise ValueError("天井の平らな部分が評価板の縁より狭くなります.fillet を小さく") + sphere = trimesh.creation.icosphere(subdivisions=sphere_subdivisions).vertices + + def solid(offset: float) -> trimesh.Trimesh: + z_top, z_bottom = rim_z + offset, rim_z - depth - offset + c = y_top - slope * rim_z + offset * norm # 傾いた壁: y - slope·z = c + items = [] + for z, is_top in ((z_top, True), (z_bottom, False)): + for sx in (-1.0, 1.0): + for is_plus_y in (True, False): + r = (top_edge_fillet if (is_top and is_plus_y) else fillet) + offset + zc = z - r if is_top else z + r + xc = sx * (half_x + offset - r) + yc = (c - r * norm + slope * zc) if is_plus_y else (y_min - offset + r) + items.append((np.array([xc, yc, zc]), r)) + return _rounded_polytope(items, sphere) + + opening = trimesh.creation.box(extents=[2 * hx_in, 2 * hy_in, 2 * thickness + 2.0]) + opening.apply_translation([0.0, 0.0, rim_z]) + mesh = trimesh.boolean.difference([solid(thickness), solid(0.0), opening], engine="manifold") + if not mesh.is_watertight: + raise ValueError("生成メッシュが watertight になりませんでした") + return mesh + + def _parse_args(argv: list[str] | None = None) -> argparse.Namespace: """コマンドライン引数をパースして返す.""" parser = argparse.ArgumentParser( diff --git a/scripts/sweep_candidate_layouts.py b/scripts/sweep_candidate_layouts.py index e136ea8..a5dca02 100644 --- a/scripts/sweep_candidate_layouts.py +++ b/scripts/sweep_candidate_layouts.py @@ -53,6 +53,7 @@ from generate_cube_housing import ( # noqa: E402 build_cube_housing, build_rounded_cube_housing, + build_rounded_sloped_box_housing, build_sloped_box_housing, ) @@ -307,6 +308,37 @@ replace(_base, name=f"{_base.name}_N", note=f"{_base.note}・鼻の穴あり", nose=True), ) +# 画面が今と同じ範囲で見えることと鼻の穴は必須(PLAN_03).その中での改善を F3_y80_s20_b1_N から探す +# A. 内側の角を丸める.天井と +Y 側の壁の稜は評価板の上の縁に近いので SLOPED_TOP_EDGE_FILLET まで +SLOPED_TOP_EDGE_FILLET = 8.0 +_best = next(c for c in CANDIDATES if c.name == "F3_y80_s20_b1_N") +for _r in (10.0, 20.0): + CANDIDATES += ( + replace(_best, name=f"{_best.name}_R{_r:g}", fillet=_r, + note=f"{_best.note}・内側の角を R{_r:g}(上の縁の稜は " + f"R{min(_r, SLOPED_TOP_EDGE_FILLET):g})"), + ) +# B. LED の高さ(基準は Z = -25) +for _z in (-15.0, -35.0): + CANDIDATES += ( + replace(_best, name=f"{_best.name}_z{-_z:g}", led_dz=_z - (-65.95), + note=f"{_best.note}・LED 高さ Z={_z:g}"), + ) +# A と B の組み合わせ(R20・LED を奥へ).奥ほど上の壁が低く,丸めた稜もあるので,左右の基板の +# ずらしは基板カバーが壁に食い込まない量まで(Z=-35 で +20 mm,Z=-45 で +16 mm が上限) +for _shift, _z in ((20.0, -35.0), (16.0, -45.0)): + _boards = tuple( + Board(b.label, b.angle_deg, (b.led_xy[0], b.led_xy[1] + _shift)) + if b.label in ("right", "left") else b + for b in _sloped_boards(-80.0, False) + ) + CANDIDATES += ( + replace(_best, name=f"F3_y80_s{_shift:g}_b1_N_R20_z{-_z:g}", boards=_boards, fillet=20.0, + led_dz=_z - (-65.95), + note=f"上面を傾けた箱・左右を +Y へ {_shift:g} mm・鼻の穴あり・内側の角を R20・" + f"LED 高さ Z={_z:g}"), + ) + # 遮光板: LED 発光面から BAFFLE_GAP 上に置く厚さ BAFFLE_THICKNESS の板.LED のどの点からも # 評価板の裏面(Z = -4.5,±49.5 × ±51)が直接見えない大きさにし,BAFFLE_MARGIN だけ広げる BAFFLE_GAP = 10.0 @@ -429,7 +461,7 @@ ) -> list[dict]: suffix = f"_R{fillet:g}" if fillet > 0 else "" if y_min is not None: - suffix = f"_傾斜_y{-y_min:g}" + suffix = f"_傾斜_y{-y_min:g}" + (f"_R{fillet:g}" if fillet > 0 else "") if nose: plain = MESH_DIR / f"箱形_L{box_size:g}{suffix}.stl" _box_meshes(yaml_dir, box_size, fillet, y_min) # 穴の無い筐体を先に用意する @@ -440,7 +472,15 @@ housing = MESH_DIR / f"箱形_L{box_size:g}{suffix}.stl" window = MESH_DIR / f"箱形_L{box_size:g}_スマホ側の窓.stl" MESH_DIR.mkdir(parents=True, exist_ok=True) - if not housing.exists() and y_min is not None: + if not housing.exists() and y_min is not None and fillet > 0: + build_rounded_sloped_box_housing( + half_x=SLOPED_HALF_X, y_min=y_min, y_top=SLOPED_Y_TOP, slope=SLOPED_SLOPE, + depth=box_size, thickness=BOX_THICKNESS, + board_half_x=BOARD_HALF[0], board_half_y=BOARD_HALF[1], + rim_inset=RIM_INSET, rim_z=RIM_Z, + fillet=fillet, top_edge_fillet=min(fillet, SLOPED_TOP_EDGE_FILLET), + ).export(housing) + elif not housing.exists() and y_min is not None: build_sloped_box_housing( half_x=SLOPED_HALF_X, y_min=y_min, y_top=SLOPED_Y_TOP, slope=SLOPED_SLOPE, depth=box_size, thickness=BOX_THICKNESS,