#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ 液滴 / 节点融合(第四十一刀)—— 甲方第二批参照:metaball 家族 八张参照里六张是同一个语法:圆点之间长出**凹颈**,融成一整块 (琵琶湖ホテル、BIOPUS、FARCA、ZEOUR、NFLUENCE、I-DO), 另两张是近亲(波形、圆点环)。 为什么这一族值得单独开一刀:**它是第一个既流行、又落在自有字理上的语法。** · metaball 的本质不是"点被线连起来",是**两个独立的东西长成了一个**。 · 《说文》「叡,深明也。**通也**」;段玉裁「能容而後能明」; 《彖》「天地交而万物**通**也」。⇒ **颈就是"交",融合就是"通"。** · 一家卖架构整合与系统打通的咨询公司,画"节点长在一起"是字面意义上的本行。 前面四十刀要么借古钱、借印、借山、借卦,这一刀不用借。 三族,全部单因子: A 融合度 —— 两珠,只改圆心距 d。这一族真正的生死线在**颈宽**: 颈一细,缩到 16px 就断成两颗豆。所以把 d 扫开,逐档量连通体。 B 母题 —— 双珠 / 三合 / 四合 / 六环留心 / 五珠 / 递生长臂 / 频环 … C 异常 —— 一颗出列(脱离接触)/ 一颗放大 / 交叠调子(参照图那种半透明叠色) 解析对照(答案由构造决定):两圆完全重合必 1 个连通体;两圆远隔必 2 个。 """ import importlib.util import json import math import os HERE = os.path.dirname(os.path.abspath(__file__)) def load(name, fn): sp = importlib.util.spec_from_file_location(name, os.path.join(HERE, fn)) m = importlib.util.module_from_spec(sp) sp.loader.exec_module(m) return m r2 = load("r2", "ring2.py") CH = json.load(open(os.path.join(HERE, "_wm-chars.json"), encoding="utf-8"))["chars"] RED, INK, WHITE, TAN = "#C41E3A", "#26221E", "#FFFFFF", "#81565D" VB = 120.0 CC = 60.0 # --------------------------------------------------------------- metaball 几何 def field(nodes, x, y): s = 0.0 for cx, cy, r in nodes: dx, dy = x - cx, y - cy d2 = dx * dx + dy * dy s += (r * r) / d2 if d2 > 1e-9 else 1e9 return s def contour(nodes, T=1.0, n=200, box=(2.0, 2.0, 118.0, 118.0)): """纯 Python marching squares。返回若干闭合环(不判向,交给 evenodd 处理嵌套)。""" x0, y0, x1, y1 = box hs = (x1 - x0) / (n - 1) vs = (y1 - y0) / (n - 1) F = [[0.0] * n for _ in range(n)] for j in range(n): y = y0 + j * vs for i in range(n): F[j][i] = field(nodes, x0 + i * hs, y) pts = {} def edge(e, i, j): """e: 0=top 1=right 2=bottom 3=left,返回该边上的插值交点。""" key = (e, i, j) if e in (0, 2) else (e, j, i) if key in pts: return pts[key] if e == 0: a, b = F[j][i], F[j][i + 1] t = (T - a) / (b - a) if b != a else 0.5 p = (x0 + (i + t) * hs, y0 + j * vs) elif e == 2: a, b = F[j + 1][i], F[j + 1][i + 1] t = (T - a) / (b - a) if b != a else 0.5 p = (x0 + (i + t) * hs, y0 + (j + 1) * vs) elif e == 3: a, b = F[j][i], F[j + 1][i] t = (T - a) / (b - a) if b != a else 0.5 p = (x0 + i * hs, y0 + (j + t) * vs) else: a, b = F[j][i + 1], F[j + 1][i + 1] t = (T - a) / (b - a) if b != a else 0.5 p = (x0 + (i + 1) * hs, y0 + (j + t) * vs) pts[key] = p return p # 位:tl=1 tr=2 br=4 bl=8。表里只列【真的被穿越】的两条边 —— # case 9 是 tl|bl 在内,左边两端点都在内、根本没被穿越, # 第一版误写成 (0,3),于是往一个不存在交点上连线,留下 66 个度为 1 的悬点, # 环数从 1 炸到 41。正确是 top→bottom。 TAB = {1: [(0, 3)], 2: [(0, 1)], 3: [(3, 1)], 4: [(1, 2)], 6: [(0, 2)], 7: [(3, 2)], 8: [(2, 3)], 9: [(0, 2)], 11: [(1, 2)], 12: [(3, 1)], 13: [(0, 1)], 14: [(0, 3)]} segs = [] for j in range(n - 1): for i in range(n - 1): c = ((1 if F[j][i] >= T else 0) | (2 if F[j][i + 1] >= T else 0) | (4 if F[j + 1][i + 1] >= T else 0) | (8 if F[j + 1][i] >= T else 0)) if c == 0 or c == 15: continue if c in (5, 10): ctr = (F[j][i] + F[j][i + 1] + F[j + 1][i] + F[j + 1][i + 1]) / 4.0 if (ctr >= T) == (c == 5): segs.append((edge(0, i, j), edge(3, i, j))) segs.append((edge(1, i, j), edge(2, i, j))) else: segs.append((edge(0, i, j), edge(1, i, j))) segs.append((edge(2, i, j), edge(3, i, j))) continue for a, b in TAB[c]: segs.append((edge(a, i, j), edge(b, i, j))) def key(p): return (round(p[0], 5), round(p[1], 5)) adj = {} for si, (a, b) in enumerate(segs): adj.setdefault(key(a), []).append(si) adj.setdefault(key(b), []).append(si) loose = [q for q, v in adj.items() if len(v) != 2] if loose: raise AssertionError("等值面有 %d 个悬点(应为 0)—— 查 marching squares 表" % len(loose)) used = [False] * len(segs) loops = [] for si in range(len(segs)): if used[si]: continue loop = [segs[si][0], segs[si][1]] used[si] = True cur = key(segs[si][1]) guard = 0 while cur != key(loop[0]) and guard < 100000: guard += 1 nxt = None for s2 in adj.get(cur, ()): if not used[s2]: nxt = s2 break if nxt is None: break used[nxt] = True a, b = segs[nxt] p = b if key(a) == cur else a loop.append(p) cur = key(p) loops.append(loop) return loops def path_d(nodes, T=1.0, n=200): loops = contour(nodes, T, n) if not loops: raise AssertionError("等值面空 —— 节点半径或阈值给错了") out = [] for lp in loops: out.append("M " + " L ".join("%.2f %.2f" % (x, y) for x, y in lp) + " Z") return " ".join(out), len(loops) def ring_nodes(k, rad, r, phase=90.0, radii=None, rr=None): """k 个节点均分在半径 rad 的圆上。radii 可逐点给不同半径(做"一颗放大")。""" out = [] for i in range(k): a = math.radians(phase + 360.0 * i / k) out.append((CC + rad * math.cos(a), CC + rad * math.sin(a), r if radii is None else radii[i])) return out def pair(d, r): return [(CC - d / 2.0, CC, r), (CC + d / 2.0, CC, r)] def neck(d, r): """两等珠融合颈宽(解析):2·sqrt(2r² − d²/4)。≤0 即已断开。""" v = 2.0 * r * r - d * d / 4.0 return 2.0 * math.sqrt(v) if v > 0 else 0.0 # --------------------------------------------------------------- 三族候选 FAM_A = ("A 融合度:颈就是生死线", "两珠,只改圆心距 d。颈宽按解析式 2√(2r²−d²/4) 递减;" "缩到 16px 时颈先断 —— 断的那一刻,标志从「一个物」退化成「两颗豆」。", [("A1 d=26 已融成一体", pair(26.0, 20.0), "d 远小于 2r,腰部比珠径还宽(颈/珠径 1.26)—— 等于没有颈,一整颗椭圆。上限对照。"), ("A2 d=34", pair(34.0, 20.0), "颈/珠径 1.13,腰还比珠粗,颈只是刚要显形。"), ("A3 d=42", pair(42.0, 20.0), "颈开始明显收细 —— 这是最好看的一段,也是最危险的一段。"), ("A4 d=50", pair(50.0, 20.0), "再细一档。"), ("A5 d=56", pair(56.0, 20.0), "临界:解析颈宽已接近 0,16px 必断。")]) FAM_B = ("B 母题", "同一套液滴语法下的不同「数」。每一个数都对应我们自己的东西,不借象。", [("B1 二珠·通", pair(38.0, 21.0), "两个系统长成一个。「叡,通也」。最小、最强的那一格。"), ("B2 三合", ring_nodes(3, 19.0, 17.0, 90.0), "三才/三层。旋转 120°,琵琶湖ホテル那种。"), ("B3 四合", ring_nodes(4, 19.0, 16.0, 45.0), "四方/四字 睿新致远。"), ("B4 五珠", ring_nodes(4, 21.0, 15.0, 90.0) + [(CC, CC, 15.0)], "四合一中心。中心那颗把孔填掉 —— 对照 J2「只留一个封闭负形」。"), ("B5 六环留心", ring_nodes(6, 32.0, 12.0, 90.0), "六爻/六合,中间留一个孔。BIOPUS 那种。" "R=25/r=15.5 第一版留不住孔:中心场 = 6r²/R² = 2.31 > 1 已被填死。" "留孔的硬条件是 R > r√6,融合的硬条件是 R < 2.83r —— 两条件之间只剩" " 2.45r < R < 2.83r 这一条窄缝,这里取 R=32 / r=12(中心场 0.84,实测 2 环)。"), ("B6 递生长臂", [(CC - 22, CC + 20, 20.0), (CC, CC, 15.0), (CC + 20, CC - 20, 10.0), (CC + 31, CC - 31, 5.0)], "由大到小一路甩出去 —— 致远。FARCA 那条尾巴。"), ("B7 频环", ring_nodes(9, 26.0, 0.0, 90.0, radii=[13 + 6.0 * math.sin(3 * math.radians(360.0 * i / 9)) for i in range(9)]), "一圈半径按正弦起伏的珠子 —— 把 BrainFrequency 那个波形翻成环。")]) FAM_C = ("C 异常", "参照图那一族几乎每张都留一处不可复制的偏差。这一族试三种做法。", [("C1 一颗出列", pair(38.0, 21.0) + [(CC, 15.0, 6.5)], "主体不动,上方放一颗**脱离接触**的小珠。第一版放在 y=20 时其实没脱开 —— " "两珠合起来的场在 y≈33 处仍 >1,被一根看不见的细颈连着,环数诚实地报了 1。" "挪到 y=15 才真是两颗。"), ("C2 一颗放大", ring_nodes(4, 19.0, 15.0, 45.0, radii=[23.0, 15.0, 15.0, 15.0]), "四合里有一颗明显大 —— 打破旋转对称,避免读成齿轮。"), ("C3 交叠调子", pair(44.0, 22.0), "参照图那种半透明叠色(两色相交出第三色)。这里用朱砂+檀色叠," "但**印刷与单色化时是风险**,只作试探。")]) FAMS = [FAM_A, FAM_B, FAM_C] CSS = """ *{box-sizing:border-box} body{margin:0;background:#F7F4EF;color:#4F4A42; font:17px/1.9 "Songti SC","Noto Serif SC",Georgia,serif;-webkit-font-smoothing:antialiased} .wrap{max-width:1240px;margin:0 auto;padding:46px 32px 100px} code{font:13.5px/1.5 ui-monospace,Menlo,monospace;background:#EFEAE1;padding:1px 5px} .ey{font:12px/1.4 "PingFang SC",Inter,sans-serif;letter-spacing:.18em; text-transform:uppercase;color:#8A8377} h1{font-size:50px;line-height:1.16;color:#26221E;margin:12px 0 16px;font-weight:600} h1 em{font-style:normal;color:#C41E3A} h2{font-size:25px;color:#26221E;margin:52px 0 8px;font-weight:600} h2 .ax{font:13px/1.6 "PingFang SC",Inter,sans-serif;color:#8A8377;font-weight:400; margin-left:12px;display:block} p{max-width:92ch;margin:10px 0} .lede{font-size:19px;color:#26221E;max-width:80ch} .j{border-left:2px solid #C41E3A;padding:3px 0 3px 18px;margin:14px 0;color:#26221E;max-width:96ch} .grid{display:grid;grid-template-columns:repeat(5,1fr);gap:14px;margin:16px 0 6px} .c{background:#fff;border:1px solid #EFEAE1;padding:14px 12px 16px} .c.pick{border-color:#C41E3A;box-shadow:0 0 0 1px #C41E3A inset} .nm{font:650 13px/1.35 "PingFang SC",Inter,sans-serif;color:#26221E;min-height:34px} .fig{text-align:center;padding:6px 0} .mt{font:11px/1.6 "PingFang SC",Inter,sans-serif;color:#8A8377; font-variant-numeric:tabular-nums;text-align:center} .mt .bad{color:#C41E3A;font-weight:700} .mt .good{color:#0f7b3b;font-weight:700} .nt{font-size:12.5px/1.6 "PingFang SC",Inter,sans-serif;color:#4F4A42; border-top:1px solid #EFEAE1;margin-top:8px;padding-top:7px} table{border-collapse:collapse;width:100%;margin:14px 0; font:13px/1.6 "PingFang SC",Inter,sans-serif} th,td{padding:9px 11px;border-bottom:1px solid #C3BDB1;text-align:left} th{font-size:11px;letter-spacing:.11em;text-transform:uppercase;color:#8A8377;font-weight:500} td.n,th.n{text-align:right;font-variant-numeric:tabular-nums;white-space:nowrap} .lk{display:flex;gap:26px;align-items:flex-start;flex-wrap:wrap; background:#fff;border:1px solid #EFEAE1;padding:22px 24px;margin:14px 0} footer{margin-top:56px;padding-top:16px;border-top:1px solid #C3BDB1; font:12.5px/1.7 "PingFang SC",Inter,sans-serif;color:#8A8377} """ def art(nodes, px, key, fill=RED, extra=""): d, nloop = path_d(nodes) return ('' '%s' % (VB, VB, px, px, key, fill, d, extra)), nloop def svg_plain(d, px, fill=RED, op=1.0): return ('' '' % (VB, VB, px, px, fill, op, d)) def lockup(nodes, px, ccol=INK, fill=RED): d, _n = path_d(nodes) h, cw = 26.0, 30.0 total = 4 * cw x0 = (VB - total) / 2.0 + cw / 2.0 cal = "".join(r2.char_svg(i, x0 + i * cw, 150.0, h, ccol) for i in range(4)) return ('' '%s' % (VB, px, fill, d, cal)) def build(): P = ['' '' '液滴 · 节点融合
'] P.append('
Cut 41 · 2026-10-14 · metaball 家族 · 颈宽是生死线 · repo 零改动
') P.append('

节点:颈就是「通」

') P.append('

八张里六张是同一个语法:圆点之间长出凹颈、融成一整块。' '这一族值得单独开一刀,因为它是第一个既流行、又落在我们自己的字理上的语法 —— ' 'metaball 讲的不是"点被线连起来",是"两个东西长成了一个",' '而《说文》给睿的定义正是「深明也,通也」,《彖》曰「天地交而万物通也」。

') P.append('
这一族的生死线只有一条,而且可以算。' '两珠之间的颈宽解析式 = 2√(2r² − d²/4)。颈一细,缩到 16px 就先断 —— ' '断的那一刻,标志从「一个物」退化成「两颗豆」。' '所以 A 族只改圆心距,逐档量 16px 连通体数:它掉到 2 的那一档,就是这族的分辨率天花板。
') rows = [] for title, axnote, items in FAMS: P.append('

%s%s

' % (title, axnote)) P.append('
') for nm, nodes, why in items: key = nm.split()[0] a, nloop = art(nodes, 150, key) nk = neck(nodes[1][0] - nodes[0][0], nodes[0][2]) if key.startswith("A") else None rows.append((nm, key, len(nodes), nloop, nk)) cls = "c pick" if key in ("B1", "A3") else "c" P.append('
%s
%s
' '
%d 珠 · 环 %d · 颈/珠径 %s
' '
%s
' % (cls, nm, a, len(nodes), nloop, ("%.2f" % nk) if nk is not None else "—", why)) P.append('
') P.append('

锁定液滴 + 睿新致遠真迹

') P.append('
') for nm, nodes, why in list(FAM_B[2]): key = nm.split()[0] if key not in ("B1", "B5", "B6"): continue P.append('
%s
%s · 朱砂+墨字
' % (lockup(nodes, 190), key)) P.append('
%s' '
%s · 暖墨底反白
' % (lockup(nodes, 190, ccol=WHITE, fill=WHITE), key)) P.append('
') P.append('

实测

') P.append('' '' '' '') for nm, key, nnode, nloop, nk in rows: P.append('' '' '' '' '' '' % (nm, nnode, ("%.1f" % nk) if nk is not None else "—", key, key, key, key, key)) P.append('
格珠数颈/珠径环数@512墨率@512颈@512颈@1616px 连通体
%s%d%s……………
') P.append('

16px 连通体是这一刀的主判据:=1 说明颈活到了 16 像素,' '≥2 说明已经断成豆子。

' '

换掉了一个指标。原来这两列是「最细特征」(全局 minRun),' '实测发现它对全弯轮廓不可信:最胖的 A1 报 1.00px、比最瘦的 A5 的 4.00px ' '还小 —— 非单调即指标失效,原因是弧形边的抗锯齿毛刺本身就只有 1px。' '改成沿中轴量腰:过形心那一列上、包含形心的那段连续墨长。' '两珠水平排布时它就是颈,且对 A 族可以和解析式 2√(2r²−d²/4) 对账。

') P.append('

仪器对照:计算中…

') P.append('') P.append(r"""""") P.append('
') return "".join(P) if __name__ == "__main__": html = build() out = os.path.join(HERE, "goo.html") with open(out, "w", encoding="utf-8") as f: f.write(html) os.makedirs(os.path.join(HERE, "assets-goo"), exist_ok=True) for title, axnote, items in FAMS: for nm, nodes, why in items: key = nm.split()[0] d, nloop = path_d(nodes) with open(os.path.join(HERE, "assets-goo", key + ".svg"), "w", encoding="utf-8") as fh: fh.write('' '' % (VB, VB, RED, d)) nk = neck(nodes[1][0] - nodes[0][0], nodes[0][2]) if key.startswith("A") else None if nk is not None: nk /= 2.0 * nodes[0][2] print("%-4s 珠 %d 环 %d 颈/珠径 %s" % (key, len(nodes), nloop, ("%.2f" % nk) if nk is not None else "—")) print("goo.html %s B" % format(len(html.encode("utf-8")), ","))