feat(spatial): 近贴合家族与容差扫描
稳定性家族加 clearance 参数(把上块抬离底座 0/1/2/4 格,1 格 = 0.25mm), 新增 area.gap1/2/4。extract 加 tol 子命令:对每个间隙扫容差,问两件事——会不会 提取出一条不存在的 T-P 接触,以及这条假边会不会被检查器接受为有效凭证。
This commit is contained in:
1 parent
e798d8fc43
commit
b46c76ce9a
2 files changed
+58
-4
No files matched your search
@@ -178,8 +178,49 @@ def report(n: int = 32) -> None:
|
||||
print("余隙 = 互不接触的零件表面之间的最小距离,说明容差有没有被真正考验")
|
||||
|
||||
|
||||
GAP_FAMILIES = (("area.sup2", 0), ("area.gap1", 1), ("area.gap2", 2), ("area.gap4", 4))
|
||||
|
||||
|
||||
def report_tolerance(n: int = 8) -> None:
|
||||
"""Does the distance tolerance decide anything, and what does it cost.
|
||||
|
||||
For every clearance the upper block sits at, sweep the tolerance and ask two
|
||||
questions: does an edge between the block and its (absent) pedestal appear,
|
||||
and if so does the checker accept that edge as a certificate. A tolerance
|
||||
that fuses two parts 0.25mm apart does not merely add noise -- it forges a
|
||||
support that validates.
|
||||
"""
|
||||
tols = (0.0, 0.5, 1.0, 2.0, 4.0)
|
||||
print(f"{'family':10s} {'间隙':>4s} " + " ".join(f"{t:>9.1f}" for t in tols))
|
||||
print("-" * 68)
|
||||
for fam, gap in GAP_FAMILIES:
|
||||
cells = []
|
||||
for tol in tols:
|
||||
got = forged = total = 0
|
||||
for i in range(n):
|
||||
sc = generator.make(fam, seed=7, index=i)
|
||||
edges = extract_edges(sc.obs.entities, tol=tol)
|
||||
world = FullState(entities=list(sc.obs.entities), edges=edges)
|
||||
tp = [e for e in edges if {e.a, e.b} == {"T", "P"}]
|
||||
total += 1
|
||||
if tp:
|
||||
got += 1
|
||||
forged += int(checker.validate_evidence(
|
||||
world, Query(kind="stability", a="T"), [tp[0].eid]))
|
||||
mark = "ok" if gap == 0 else ("!" if forged else " ")
|
||||
cells.append(f"{got:2d}/{total} {mark:2s}")
|
||||
print(f"{fam:10s} {gap:4d} " + " ".join(f"{c:>9s}" for c in cells))
|
||||
print()
|
||||
print("单元格 = 提取到 T-P 边的样本数 / 总数;ok = 该边合法(间隙为 0,本来就贴着)")
|
||||
print("! = 该边被检查器当成有效凭证,但零件其实没有接触 —— 容差过大伪造了支撑")
|
||||
print("间隙单位 0.25mm;真实装配的余隙是 0.2mm 级,即 1 格")
|
||||
|
||||
|
||||
def main(argv=None) -> int:
|
||||
argv = list(sys.argv[1:] if argv is None else argv)
|
||||
if argv and argv[0] == "tol":
|
||||
report_tolerance(int(argv[1]) if len(argv) > 1 else 8)
|
||||
else:
|
||||
report(int(argv[0]) if argv else 32)
|
||||
return 0
|
||||
|
||||
|
||||
+17
-4
@@ -32,6 +32,9 @@ FAMILIES = {
|
||||
"area.free": {"domain": "stability", "n_blocks": 2, "hidden": 0, "free": 1},
|
||||
"area.sup3h": {"domain": "stability", "n_blocks": 3, "hidden": 1},
|
||||
"area.sup2d": {"domain": "stability", "n_blocks": 2, "hidden": 0, "notch": 1},
|
||||
"area.gap1": {"domain": "stability", "n_blocks": 2, "hidden": 0, "clearance": 1},
|
||||
"area.gap2": {"domain": "stability", "n_blocks": 2, "hidden": 0, "clearance": 2},
|
||||
"area.gap4": {"domain": "stability", "n_blocks": 2, "hidden": 0, "clearance": 4},
|
||||
"dof.c6": {"domain": "freedom", "n_cons": 6, "hidden": 0},
|
||||
"dof.c6r": {"domain": "freedom", "n_cons": 7, "hidden": 0},
|
||||
"dof.c6h": {"domain": "freedom", "n_cons": 6, "hidden": 1},
|
||||
@@ -129,7 +132,8 @@ def _build_connection(rng, n_paths: int, hidden: int):
|
||||
# stability: stacked blocks, optional hidden pedestal
|
||||
|
||||
|
||||
def _build_stability(rng, n_blocks: int, hidden: int, free: int = 0, notch: int = 0):
|
||||
def _build_stability(rng, n_blocks: int, hidden: int, free: int = 0, notch: int = 0,
|
||||
clearance: int = 0):
|
||||
if free:
|
||||
# the minimal pair against area.sup2h: here T has exactly one contact and
|
||||
# that contact leads to a block which itself hangs in the air. Nothing
|
||||
@@ -156,16 +160,22 @@ def _build_stability(rng, n_blocks: int, hidden: int, free: int = 0, notch: int
|
||||
# is exactly what the report kept showing.
|
||||
dx = rng.choice((-13, -6, 0, 3, 6, 13))
|
||||
dy = rng.choice((-9, 0, 0, 0, 9))
|
||||
# clearance lifts the upper block off its pedestal by a few grid units (one
|
||||
# grid unit is 0.25mm). At 0 the two surfaces touch exactly; at 1 they are
|
||||
# 0.25mm apart, which is the regime real assemblies live in and the regime a
|
||||
# distance tolerance actually has to decide.
|
||||
cl = int(clearance)
|
||||
ents = [Entity("G", "ground", attrs={"plane": 0}),
|
||||
Entity("P", "block", attrs={"box": [40, 40, 0, 60, 60, 20]}),
|
||||
Entity("T", "block", attrs={"box": [42 + dx, 42 + dy, 20, 58 + dx, 58 + dy, 36]}),
|
||||
Entity("T", "block", attrs={"box": [42 + dx, 42 + dy, 20 + cl,
|
||||
58 + dx, 58 + dy, 36 + cl]}),
|
||||
Entity("D", "block", attrs={"box": [80, 40, 0, 100, 60, 16]})]
|
||||
edges = [Edge("kPG", "contact", "P", "G"), Edge("kPT", "contact", "T", "P"),
|
||||
Edge("kDG", "contact", "D", "G")]
|
||||
top = None
|
||||
if n_blocks >= 3:
|
||||
ents.append(Entity("U", "block",
|
||||
attrs={"box": [44 + dx, 44 + dy, 36, 56 + dx, 56 + dy, 48]}))
|
||||
attrs={"box": [44 + dx, 44 + dy, 36 + cl, 56 + dx, 56 + dy, 48 + cl]}))
|
||||
edges.append(Edge("kTU", "contact", "U", "T"))
|
||||
top = "U"
|
||||
vis_edges = {e.eid for e in edges}
|
||||
@@ -195,6 +205,8 @@ def _build_stability(rng, n_blocks: int, hidden: int, free: int = 0, notch: int
|
||||
# that removes P, so "removed something" no longer implies "answer false"
|
||||
query = Query(kind="stability", a="T")
|
||||
r = rng.random()
|
||||
if clearance:
|
||||
return ents, edges, query, vis_edges, vis_ents, layers, ["front", "iso"], {"length": "mm", "per_unit": 1}
|
||||
if not hidden:
|
||||
harmless = top or "D"
|
||||
if r < 0.4:
|
||||
@@ -264,7 +276,8 @@ def _build_freedom(rng, n_cons: int, hidden: int, no_edit: int = 0, notch: int =
|
||||
_BUILDERS = {
|
||||
"connection": lambda rng, spec: _build_connection(rng, spec["n_paths"], spec["hidden"]),
|
||||
"stability": lambda rng, spec: _build_stability(rng, spec["n_blocks"], spec["hidden"],
|
||||
spec.get("free", 0), spec.get("notch", 0)),
|
||||
spec.get("free", 0), spec.get("notch", 0),
|
||||
spec.get("clearance", 0)),
|
||||
"freedom": lambda rng, spec: _build_freedom(rng, spec["n_cons"], spec["hidden"],
|
||||
spec.get("no_edit", 0), spec.get("notch", 0)),
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user