ARTICLE DETAIL

资讯详情

深耕郑州网站建设与运营推广的一线实战洞察。

彭罗斯非周期镶嵌(Penrose Tiling):Canvas 五次对称生成艺术

彭罗斯非周期镶嵌(Penrose Tiling):Canvas 五次对称生成艺术 在 1974 年之前经典晶体学与几何学界公认一条铁律“任何能够无缝铺满平面的二维密铺瓷砖在数学上必定具备平移周期性Periodic Translation且其旋转对称性只能是 2、3、4 或 6 重对称绝对不可能存在 5 重旋转对称性Fivefold Symmetry”然而英国著名数学物理学家、诺贝尔物理学奖得主罗杰·彭罗斯Roger Penrose以惊世骇俗的数学洞察彻底推翻了这一定论。他仅仅凭借两块极其简单的菱形瓷砖厚菱形 Fat Rhombus与薄菱形 Thin Rhombus菱形的内角全部由黄金分割比$\Phi \frac{1\sqrt{5}}{2} \approx 1.618$与五角星几何严格决定$72^\circ/108^\circ$ 与 $36^\circ/144^\circ$按照特定的匹配规则无缝铺满整个二维平面时令人震撼的几何奇迹发生了整张平面在局部呈现出完美的五次旋转对称性如五角星与十边形结构但在整体上无论你沿着哪个方向平移多远整幅铺砖图案在数学上永远绝不重复非周期性 Aperiodic Tiling彭罗斯镶嵌后来直接启发了物理学家丹·谢赫特曼Dan Shechtman发现了自然界中的“准晶体Quasicrystals”并因此荣获 2011 年诺贝尔化学奖。在生成艺术领域彭罗斯镶嵌是纯粹几何逻辑与神圣几何秩序最完美的结晶。本文将深入推导彭罗斯 P3 菱形镶嵌的Robinson 黄金三角形递归细分算法Deflation Algorithm并在 HTML5 Canvas 中手写一个带有高阶色阶渐变的彭罗斯生成艺术画卷。Robinson 黄金三角形递归细分Deflation代数推导为了在计算机中严密且高效地生成任意大尺寸的彭罗斯镶嵌直接使用“搭积木试凑法”会导致组合爆炸最优雅的算法是将铺砖问题转化为两种 Robinson 黄金等腰三角形的递归分裂细分Deflation┌─────────────────────────────────────────────────────────┐ │ Robinson 黄金三角形分类 │ └────────────────────────────┬────────────────────────────┘ │ ┌──────────────────────────────────────┴──────────────────────────────────────┐ ▼ 黄金大三角形 (Type A / 顶角 108°, 底角 36°) ▼ 黄金小三角形 (Type B / 顶角 36°, 底角 72°) ┌─────────────────────────────────────────────────────────────┐ ┌─────────────────────────────────────────────────────────────┐ │ 细分规则 (Deflation): │ │ 细分规则 (Deflation): │ │ 1 个大三角形 A 裂变分解为: │ │ 1 个小三角形 B 裂变分解为: │ │ - 1 个新的小尺度大三角形 A │ │ - 1 个小尺度大三角形 A │ │ - 1 个新的小尺度小三角形 B │ │ - 1 个小尺度小三角形 B │ └─────────────────────────────────────────────────────────────┘ └─────────────────────────────────────────────────────────────┘细分内分点坐标黄金比例计算公式设三角形三顶点为 $\mathbf{A}, \mathbf{B}, \mathbf{C}$。对于大三角形 A$\angle A 108^\circ, AB AC$在边 $BC$ 上取黄金内分点 $\mathbf{P}$$$\mathbf{P} \mathbf{A} \frac{1}{\Phi} (\mathbf{B} - \mathbf{A})$$三角形分裂为 $\triangle C P A$新的大三角形与 $\triangle C P B$新的小三角形对于小三角形 B$\angle A 36^\circ, AB AC$在边 $AB$ 上取内分点 $\mathbf{Q} \mathbf{A} \frac{1}{\Phi}(\mathbf{B} - \mathbf{A})$分裂为 $\triangle B Q C$大三角形与 $\triangle A Q C$小三角形。经过 $N$ 轮递归细分后两两相邻的黄金三角形自动拼接组合完美自发涌现出厚薄彭罗斯菱形非周期镶嵌纯 TypeScript 彭罗斯三角形递归细分引擎// penrose-tiling-engine.ts export interface Point2D { x: number; y: number; } export type TriangleType 0 | 1; // 0: 黄金大三角形(Type A), 1: 黄金小三角形(Type B) export interface GoldenTriangle { type: TriangleType; a: Point2D; b: Point2D; c: Point2D; } export class PenroseTilingEngine { private static PHI (1 Math.sqrt(5)) / 2; // 黄金比例 ≈ 1.6180339887 // 1. 生成初始的 10 个黄金三角形 (形成初始正十边形轮廓) public static generateInitialSun(cx: number, cy: number, radius: number): GoldenTriangle[] { const triangles: GoldenTriangle[] []; const center { x: cx, y: cy }; for (let i 0; i 10; i) { const angle1 ((2 * i - 1) * Math.PI) / 10; const angle2 ((2 * i 1) * Math.PI) / 10; const p1: Point2D { x: cx radius * Math.cos(angle1), y: cy radius * Math.sin(angle1) }; const p2: Point2D { x: cx radius * Math.cos(angle2), y: cy radius * Math.sin(angle2) }; if (i % 2 0) { triangles.push({ type: 0, a: center, b: p1, c: p2 }); } else { triangles.push({ type: 0, a: center, b: p2, c: p1 }); } } return triangles; } // 2. 核心单轮递归细分 (Deflation Step) public static deflate(triangles: GoldenTriangle[]): GoldenTriangle[] { const nextGeneration: GoldenTriangle[] []; for (const tri of triangles) { const { a, b, c, type } tri; if (type 0) { // 大三角形 A 分解 const p: Point2D { x: a.x (b.x - a.x) / this.PHI, y: a.y (b.y - a.y) / this.PHI, }; nextGeneration.push({ type: 0, a: c, b: p, c: b }); nextGeneration.push({ type: 1, a: p, b: c, c: a }); } else { // 小三角形 B 分解 const q: Point2D { x: b.x (a.x - b.x) / this.PHI, y: b.y (a.y - b.y) / this.PHI, }; const r: Point2D { x: b.x (c.x - b.x) / this.PHI, y: b.y (c.y - b.y) / this.PHI, }; nextGeneration.push({ type: 1, a: r, b: c, c: a }); nextGeneration.push({ type: 0, a: q, b: r, c: b }); nextGeneration.push({ type: 1, a: r, b: q, c: a }); } } return nextGeneration; } }Canvas 先锋彭罗斯镶嵌画卷渲染// penrose-canvas-stage.ts export class PenroseCanvasStage { private canvas: HTMLCanvasElement; private ctx: CanvasRenderingContext2D; constructor(canvas: HTMLCanvasElement) { this.canvas canvas; this.ctx canvas.getContext(2d)!; } public renderTiling(depth 5) { const w this.canvas.width; const h this.canvas.height; const cx w / 2; const cy h / 2; this.ctx.fillStyle #05070d; this.ctx.fillRect(0, 0, w, h); // 1. 初始化正十边形太阳轮廓 let triangles PenroseTilingEngine.generateInitialSun(cx, cy, Math.max(w, h) * 0.75); // 2. 迭代递归细分 depth 次 for (let i 0; i depth; i) { triangles PenroseTilingEngine.deflate(triangles); } // 3. 渲染几何菱形铺砖 this.ctx.lineWidth 1.0; this.ctx.strokeStyle #05070d; // 砖缝黑色描边 for (const tri of triangles) { this.ctx.beginPath(); this.ctx.moveTo(tri.a.x, tri.a.y); this.ctx.lineTo(tri.b.x, tri.b.y); this.ctx.lineTo(tri.c.x, tri.c.y); this.ctx.closePath(); // 根据三角形类型赋予先锋蓝紫撞色 if (tri.type 0) { this.ctx.fillStyle rgba(79, 70, 229, 0.85); // 黄金大三角: 沉稳极夜蓝 } else { this.ctx.fillStyle rgba(236, 72, 153, 0.85); // 黄金小三角: 鲜亮霓虹玫红 } this.ctx.fill(); this.ctx.stroke(); } } }总结彭罗斯非周期镶嵌是纯粹数学在对称性与无限性之间架起的最辉煌桥梁。通过黄金三角形的分裂细分代数模型我们在 Canvas 上以纯代码见证了五次旋转对称与永不重复的非周期秩序相互交织的宇宙奇景为先锋数字生成艺术赋予了源自诺贝尔级几何哲学的至高神圣之美。
返回列表