[Rod Stephens Books]
Index Books Python Examples About Rod Contact
[Mastodon] [Bluesky] [Facebook]
[Build Your Own Python Action Arcade!]

[Build Your Own Ray Tracer With Python]

[Beginning Database Design Solutions, Second Edition]

[Beginning Software Engineering, Second Edition]

[Essential Algorithms, Second Edition]

[The Modern C# Challenge]

[WPF 3d, Three-Dimensional Graphics with WPF and C#]

[The C# Helper Top 100]

[Interview Puzzles Dissected]

Title: Draw a Padovan spiral in Python

[A Padovan spiral drawn in Python]

This is a fairly small change to my previous post Draw Padovan triangles in Python. That post explained how you can draw Padovan triangles. The triangles have side lengths equal to the numbers in the Padovan sequence, which is defined by the recurrence relation P(i) = P(i - 2) + P(i - 3).

That post also shows that this recurrence relation is equivalent to the relation W(i) = W(i - 1) + W(i - 5). If you use those values as the triangles' side lengths, you can arrange them to form a spiral. This post shows how you can draw a Padovan spiral defined by those triangles.

Defining Arcs

[Defining an arc for a Padovan spiral drawn in Python] For each triangle in the spiral, we need to draw an arc along the triangle's base.

Let R be a triangle's side length as shown in the picture on the right. These are equilateral triangles so R is also the triangle's width.

Construct a rectangle centered at the triangle's apex and with width and height 2 &time; R, again as shown in the picture on the right. The arc we need is defined by that square. Its start angle is the triangle's "up" angle minus 60°. The arc's extent is -60°. The extent is negative because the picture draws the arc clockwise and the create_arc method measures angles counterclockwise.

Drawing Arcs

The program's code is almost identical to the code used by the previous example. The only difference is that the main app's draw method uses the following code to draw the triangle's arc.

# Draw the arc. center = triangle[0] side_length = math.dist(triangle[0], triangle[1]) square = [center[0] - side_length, center[1] - side_length, center[0] + side_length, center[1] + side_length] start = angle - 60 self.canvas.create_arc(square, style=tk.ARC, start=start, extent=-60, outline='red', width=3)

The code defines the square's center point as the triangle's first vertex. It calculates the triangle's side length and uses that and the center point to define the square. It then passes the square into the create_arc method and Bob's your uncle!

Conclusion

That's all there is to it. The program works much as the previous example did except it also draws each square's arc. See that post for details about generating the triangles.

As was the case with the Fibonacci spiral, if you have a good eye, you may notice that there's something slightly off about the spiral and for the same reason. The spiral's arcs meet smoothly with each arc tangent to those beside it, but their radii of curvature jump abruptly where they meet. Basically the spiral is smooth and its first derivative is smooth because the arcs are tangent where they meet, but the spiral's second derivative is a step function. That makes the spiral look a bit flattened where the arcs meet. This is different from most other types of spirals where the curve's second derivative is also smooth.

Download the example to experiment with it.

© 2025 Rocky Mountain Computer Consulting, Inc. All rights reserved.