
Edu Solid Geometry
Generate standard 3D solid geometry topologies (vertices and edges) for edu visuals that pair with a precision geometry kernel.
Install
npx skills add https://github.com/wy51ai/edulab --skill edu-solid-geometryWhat is this skill?
- bodies.py topology library: declares which vertices connect on which edges for standard solids
- Designed to pair with geometry_kernel.py for exact coordinates while bodies supply graph structure
- Built-in constructors include quad_pyramid, tri_pyramid, cuboid, and prism with arbitrary base vertex order
- _edge helper standardizes edge dicts with optional metadata kwargs
- Rare solids can be hand-authored edge lists when not in the built-in catalog
Adoption & trust: 1 installs on skills.sh; 416 GitHub stars.
Recommended Skills
Python Performance Optimizationwshobson/agents
Python Testing Patternswshobson/agents
Python Design Patternswshobson/agents
Python Executorqu-skills/skills
Async Python Patternswshobson/agents
Uv Package Managerwshobson/agents
Journey fit
Primary fit
Solid model assembly for rendering is product construction work—canonical Build when you are implementing lesson interactives or exam diagrams. Frontend fits because deliverables are render-ready sphere/edge models for 3D views, even though the implementation is Python topology helpers.
SKILL.md
READMESKILL.md - Edu Solid Geometry
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ bodies.py — 几何体"拓扑"库(哪些顶点、哪些棱)。 与 geometry_kernel.py 配合:kernel 负责精确坐标,bodies 负责标准棱连接, 两者合成 3D 渲染所需的 model(spheres + edges)。常见几何体在此内置; 罕见几何体可在具体题目里手写 edges。 """ def _edge(a, b, **kw): e = {"a": a, "b": b} e.update(kw) return e def quad_pyramid(apex="P", base=("A", "B", "C", "D")): """四棱锥:底面四边形 + 顶点到各底点。返回 spheres 与 edges。""" a, b, c, d = base edges = [ _edge(a, b), _edge(b, c), _edge(c, d), _edge(d, a), _edge(apex, a), _edge(apex, b), _edge(apex, c), _edge(apex, d), ] return {"spheres": [apex, a, b, c, d], "edges": edges} def tri_pyramid(apex="P", base=("A", "B", "C")): """三棱锥(四面体)。""" a, b, c = base edges = [ _edge(a, b), _edge(b, c), _edge(c, a), _edge(apex, a), _edge(apex, b), _edge(apex, c), ] return {"spheres": [apex, a, b, c], "edges": edges} def cuboid(bottom=("A", "B", "C", "D"), top=("A1", "B1", "C1", "D1")): """长方体 / 正方体:底面四边形、顶面四边形、四条竖棱。""" a, b, c, d = bottom a1, b1, c1, d1 = top edges = [ _edge(a, b), _edge(b, c), _edge(c, d), _edge(d, a), # 底面 _edge(a1, b1), _edge(b1, c1), _edge(c1, d1), _edge(d1, a1), # 顶面 _edge(a, a1), _edge(b, b1), _edge(c, c1), _edge(d, d1), # 竖棱 ] return {"spheres": [a, b, c, d, a1, b1, c1, d1], "edges": edges} def prism(bottom=("A", "B", "C"), top=("A1", "B1", "C1")): """棱柱:上下同形多边形 + 竖棱(顶点数任意,按顺序一一对应)。""" n = len(bottom) edges = [] for i in range(n): edges.append(_edge(bottom[i], bottom[(i + 1) % n])) edges.append(_edge(top[i], top[(i + 1) % n])) edges.append(_edge(bottom[i], top[i])) return {"spheres": list(bottom) + list(top), "edges": edges} #!/usr/bin/env python3 # -*- coding: utf-8 -*- """ geometry_kernel.py — 立体几何确定性计算核心(基于 sympy 精确符号运算)。 设计目标(对应方案 A):坐标、向量、最终答案全部由本模块精确算出, 根式自动化简,杜绝心算误差。同一套坐标既喂给解题文案,也喂给 3D 渲染, 保证"图、解、答"严格一致。 依赖: sympy(pip install sympy)。 坐标约定(数学坐标,z 轴向上): - 题面/公式里展示的就是这套数学坐标。 - 3D 渲染坐标采用 three.js 约定(y 轴向上):three = (x, z, y) * scale。 """ import sympy as sp sqrt = sp.sqrt # ===================== 基础工具 ===================== def V(*comps): """构造列向量(sympy.Matrix)。""" if len(comps) == 1 and isinstance(comps[0], (list, tuple)): comps = comps[0] return sp.Matrix([sp.sympify(c) for c in comps]) def midpoint(a, b): return (a + b) / 2 def normal_from_points(p, q, r): """由平面上三点求法向量(叉积),返回未化简向量。""" return (q - p).cross(r - p) def simplify_vec(v): """把向量按公因子约简到最简整系数方向(仅用于'简化取 n=...'的展示)。""" v = sp.Matrix([sp.simplify(c) for c in v]) nonzero = [c for c in v if c != 0] if not nonzero: return v g = nonzero[0] for c in nonzero[1:]: g = sp.gcd(g, c) if g != 0: cand = sp.simplify(v / g) # 若约简后仍是整数向量则采用 if all(c.is_rational for c in cand): return cand return v def line_plane_angle_sin(line_dir, normal): """线面角正弦:sinθ = |v·n| / (|v||n|),精确化简。""" v = line_dir n = normal s = sp.Abs(v.dot(n)) / (v.norm() * n.norm()) return sp.simplify(s) def line_line_angle_cos(d1, d2): """异面直线夹角余弦:cosθ = |d1·d2| / (|d1||d2|)。""" return sp.simplify(sp.Abs(d1.dot(d2)) / (d1.norm() * d2.norm())) def point_plane_distance(point, plane_point, normal): """点到平面距离:|(P - P0)·n| / |n|。""" return sp.simplify(sp.Abs((point - plane_point).dot(normal)) / normal.norm()) def dihedral_cos(A, B, C, D): """二面角 C-AB-D 的余弦:在两个半平面内各取一条垂直于棱 AB 的向量再求夹角。 AB 为棱,C 在一个面内,D 在另一个面内。返回带符号的精确余弦 (正=锐二面角,负=钝二面角)。 """ u = B - A def perp(P): w = P - A return w - (w.dot(u) / u.dot(u)) * u v1, v2 = perp(C), perp(D) return sp.simplify(v1.dot(v2) / (v1.norm() * v2.norm())) def dihedral_cos_from_normals(n1, n2): """由两半平面法向量求二面角余弦(符号依赖法向量取向,通常配合几何判断锐钝)。""" return sp.simplify(n1.dot(n2) / (n1.norm() * n2.norm())) # ===================== 体积 ===================== def volume