生成 P3 拼贴
Generating the P3 Tiling

原始链接: https://k-monk.org/blog/generating-the-p3-tiling/

彭罗斯拼贴(Penrose tilings)是一种非周期性图案,可以在不产生平移对称重复的情况下覆盖二维平面。在三种主要类型中,P3 拼贴由两种不同的菱形组成。这些图案可以通过递归细分“鲁宾逊三角形”(Robinson triangles)的特定几何规则来算法化生成。 由于计算机无法直接处理图像,这些细分规则通过“项重写”(term rewriting)有效地实现,即将三角形表示为符号项。通过递归应用这些规则,成对出现的三角形最终构成了 P3 拼贴的菱形。 计算几何中的一个重大挑战是处理浮点数的精度误差。作者通过将坐标表示为基 $\{ \zeta^3, \zeta^2, \zeta, 1 \}$(其中 $\zeta = e^{\pi i / 5}$)的线性组合解决了这一问题。这种方法使得 P3 拼贴中的所有顶点都能仅通过整数系数进行计算,从而确保了绝对精度。通过结构归纳法和分圆多项式恒等式,作者证明了这些运算在该坐标系内保持封闭,为生成复杂的无限非周期性拼贴提供了稳健的数学基础。

Hacker News最新 | 往期 | 评论 | 提问 | 展示 | 招聘 | 提交登录生成 P3 平铺 (k-monk.org)6 分,由 evakhoury 发布于 1 小时前 | 隐藏 | 往期 | 收藏 | 讨论帮助 指南 | 常见问题 | 列表 | API | 安全 | 法律 | 申请 YC | 联系 搜索:
相关文章

原文
Generating the P3 Tiling

2026-06-28

Have you heard of Penrose tilings? Today, I want to describe one algorithm you can use to generate them. My hope is that this article will serve as necessary background material for some future subjects I have in mind, the details of which I'll leave in suspense for now.

What's a tiling, in the first place? Mathematicians call any pattern that covers the 2D plane with no gaps a tiling of the 2D plane. For example, imagine a chessboard extending infinitely in all directions.

image

The set of shapes that appear in a tiling are called its prototiles. The chessboard tiling uses only one prototile, a square.

A tiling is called periodic if there is a way of shifting the whole plane in such a way that gets you back to the pattern you started at. The chessboard tiling is periodic, because, for example, you can shift the whole thing one square to the right and arrive at an identical pattern. A tiling is called aperiodic if it admits no such translational symmetry.

Penrose tilings were the first known aperiodic tilings of the plane to use only two prototiles. They were discovered by Roger Penrose in the 1970s. There are three variants that I'm aware of, known as P1, P2, and P3. P1 uses four prototiles, while P2 and P3 use only two. We'll concentrate on P3 today.

P1

image

P2 (Kites and Darts)

P3 (Rhombii)

The following set of four rules constitutes an algorithm to generate P3:

image

We have four triangles, identified by their color. Each rule explains how to replace one triangle with a set of smaller ones. Starting from any one of the four, we can recursively apply the rules. Each round of subdivision will result in a more detailed tiling of the starting triangle. Watch what happens when you execute the rules a few times using the buttons below.

These prototiles are named Robinson triangles after Raphael Robinson, who discovered them not long after Penrose first discovered P2 and P3. See section 10.3 of Tilings and Patterns by Grünbaum and Shephard, if you're interested in the history.

You may be noticing that Robinson triangles don't look like the rhombii in P3. Well, it turns out that these rules will always generate patterns of pairs. The acute triangles come in pairs, as do the obtuse ones; always joined at the base. (Except for the tiles on the rim.) So, once we're done subdividing, we can sew these pairs together to get our rhombii. The red rhombii in the rendering of P3 above are the acute pairs, and the blue rhombii are the obtuse pairs.

Why are the rules guaranteed to generate pairs in this way? Essentially, by structural induction on the subdivision rules.

I claimed the subdivision rules constitute an algorithm. That's only sort of true. The rules are given pictorally, and computers can't operate directly on pictures.

There's a framework for writing down systems like this amenable to machine execution: term rewriting. Let's see if we can express the rules as term rewriting rules. If you've not encountered term rewriting before, don't worry; I'll explain as we go. The first chapter of Term Rewriting and All That by Baader and Nipkow is a good introduction to the theory, if you want one.

A Robinson triangle is uniquely identified by its color together with its vertices. Say we choose the letters CC, DD, XX, and YY to represent the four triangle colors in the order presented above. Then, a light blue triangle with vertices pp, qq, and rr, for example, can be represented symbolically as C(p,q,r)C(p, q, r). That's a term — a piece of syntax — and we want to express the subdivision rules as manipulations of terms.

image

Above is a reproduction of the subdivision rules, with labels added for reference. Notice each subdivision rule creates at least one new vertex. The vertices created by subdivision are labeled SS and TT on the right hand side of each rule.

If we're going to express the rules as manipulations of terms, we'll need a way of expressing SS and TT in terms of the parent vertices. Robinson triangles have a nice geometric property we can leverage: SS and TT always lie 1φ\frac{1}{\varphi} of the distance along the edge, where φ\varphi is the golden ratio. The golden ratio shows up here because it's the ratio of a regular pentagon's diagonal to its side, and the Penrose tilings are all about fivefold rotational symmetry. We'll write pqp \Rightarrow q to represent the point reached by traveling 1φ\frac{1}{\varphi} of the distance from pp to qq.

With that in mind, we're ready to express the subdivision rules as term rewriting rules.

C(p,q,r)C(p, q, r) \rightarrow C(q,rq,p)×Y(r,p,rq)C(q, r \Rightarrow q, p) \; \times \; Y(r, p, r \Rightarrow q)
D(p,q,r)D(p, q, r) \rightarrow D(rp,p,q)×X(q,r,rp)D(r \Rightarrow p, p, q) \; \times \; X(q, r, r \Rightarrow p)
X(p,q,r)X(p, q, r) \rightarrow C(r,pr,pq)×X(q,r,pq)×Y(p,pq,pr)C(r, p \Rightarrow r, p \Rightarrow q) \; \times \; X(q, r, p \Rightarrow q) \; \times \; Y(p, p \Rightarrow q, p \Rightarrow r)
Y(p,q,r)Y(p, q, r) \rightarrow D(qr,r,qp)×X(qp,q,qr)×Y(r,p,qp)D(q \Rightarrow r, r, q \Rightarrow p) \; \times \; X(q \Rightarrow p, q, q \Rightarrow r) \; \times \; Y(r, p, q \Rightarrow p)

The color symbols CC, DD, XX, and YY are what are called "function symbols" in the term rewriting literature: names with a fixed arity (a fixed number of inputs). The splitting symbol \Rightarrow and the product symbol ×\times are also function symbols, but I've chosen to use them in infix form for clarity. If we were being completely formal, we'd need separate product symbols for arity 2 and for arity 3.

The lowercase letters pp, qq, and rr are variables. They range over arbitrary terms. The left hand side of each rule is a pattern; the rule can be applied whenever a satisfying instantiation of the variables in it is found.

Translated into code, this might look something like the recursive function I wrote to generate the P3 images on this page:

article on the same subject is part of what inspired me to write this. The Tilings Encyclopedia is also a useful reference. Please email me if you have questions or comments!

联系我们 contact @ memedata.com