## Introduction: Do Plants Do Maths?

Nature is awesome! There are tons of things that we can not explain in an easy way, like the hidden patterns that are a constant in many different organisms in completely different environments. Things without an obvious relationship or connection but behave in the same specific way.

Scientist have to use their most powerful tool to explain this behavior, and that is Mathematics. When using "math lenses" you can describe these complex patterns with constants, and there is one that shines above them all (at least in nature behavior) and it´s called the Golden ratio. I have uploaded pictures of plants which patterns can be described with this constant.

With the Codeblock addition in Tinkercad is now possible to simulate how a sunflower spread its seed in the most optimum way, yes with the golden ratio.

This is a great opportunity to explore mathematics, geometry, rational numbers, design, and more. This is a really cool STEM class for your high school students.

If you want to play a little bit with this in advance, you can see a series of cool videos of Vihart (vihart.com) starting with the part one here:

Now lets prepare everything for our code, so I will take advantage of this instructable to make a mini tutorial on how to use codeblocks in Tinkercad to create a sunflower. Then I will proceed with its seeds and the golden ratio simulation.

So let´s begin.

## Step 1: Create a Sunflower With Tinkercad Codeblocks (Creating One Leave)

Codeblocks is simple to use once you get the hang of it. If you know how to use Tinkercad 3D designs app this will be even easier because it will be just translate what you normally do with codes. If you haven´t used Tinkercad before, you can go there and follow a quick and sufficient tutorial to understand how it works. You can even jump this and go with codeblocks right away, there is a basic tutorial of how to use it too.

Let´s create a leave.

For any 3D design you just have to merge different shapes in order to create a more complex one. So, for me a sunflower leaf has a teardrop shape, and one way to create this is merging a cylinder and a roof, two of the basic shapes offered in Tinkercad. So let´s code this.

Select and drag a Cylinder block from the "shape" menu (blue). In the block, there are some parameters you can modify to change the shape. In this case I changed the color to yellow (the color of the leaf) and the radius to 4 and the height "H" to 3. This two parameters are the ideal size for this exercise. In any other application you can modify them to fit whatever you want to achieve. ----Check the first image.

Next, select and drag from "shape" (blue blocks in menu) the roof block. Change the color to yellow and the length "L" to 3 to match the "H" of the cylinder. ----Check the second image.

NOW YOU KNOW HOW TO ADD SHAPES.

The roof width is greater than the cylinder, so we have to modify this dimension using the "scale" block in the "modify" block menu (purple). With this block you can scale the dimensions of a shape in any of the three axis.

NOTE: the axis are represented in the middle of the workplane as color lines: red as the X axis, green as the Y axis and blue as the Z axis. Any value greater than 1, will make the shape bigger in that dimension. Any value between zero and one, will make the shape smaller in that dimension. In this case I am using 0.4 to match the width of the roof, with the diameter of the cylinder. You can just use trial and error to do find this or just use a ratio with the following formula:

Scale ratio in X axis = value in the X axis you want to achieve / value in the X axis you have.

Scale ratio in X axis = 8 (diameter of the cylinder) / 20 (default value of the roof in width) = 0.4 ----Check third image.

NOW YOU KNOW HOW TO SCALE SHAPES.

Now, every shape you add is placed right in the middle of the workplane (in every axis X, Y and Z). We need to use the "rotate" and "move" blocks to position our shape where we want it to be.

NOTE: any modification will only affect the selected shape or group of shapes. If you looked carefully, the roof was the only one affected by the scale block, because the cylinder was deselected once we added the roof. So every rotate or move block will only affect the roof (currently selected).

Let´s modify the roof. First, we need to rotate it through the X axis, 90 degrees so it is flat and parallel with the cylinder spread in the XY plane. Using the "rotate" block you can choose the axis, and the degrees you want your shape to rotate. This block can be found in the "modify" block menu (purple).

Both shapes share the same center, but we need that the roof moves to the center of the cylinder to form the teardrop shape. So we need to move the roof 5 mm in the Y axis. In the same "modify" block menu, you can choose the "move" block and specify the distance in every axis. If you don´t want it to move in a particular direction, just keep those axis value in zero.

NOTE: depending on the direction of the movement you have to consider if the desired distance is negative or positive: Negative if it is backwards or positive if it is forward, that is why, in this case, we use -5. ----Check fourth image.

NOW YOU KNOW HOW TO MOVE AND ROTATE SHAPES.

Since the cylinder and the roof are still two separate shapes, we need to merge them. For that we use the "create group" block (modify block menu). Now both shapes become one, and is selected, so every new block will affect it. For our specific situation, the center of the flower will have a 35mm brown cylinder as the flower´s center. So we need to move the leaf 35mm away from the center. We can accomplish this by using the move block that we just used before. ----Check fifth image.

To complete the petals, is a matter of finding the best wave to complete the petals around the cylinder. I came up with a simple solution, and i will describe the sequence:

"copy" block ---- This will copy the selected shape (in our case the leaf)

"Rotate" block in X axis by 180 degrees. --- This will rotate the copied leaf in the opposite direction so it can be use as the leaf in the counterpart of the flower.

"Move" block 76 mm. --- This will move the leaf to the other side of the flower. Now we have to leaves in opposites sides, its a matter to copy an rotate these two around the Z axis to complete the leaves of the sunflower.

NOTE: From the copy block the shape that was selected was the opposite leave only, so every block from it will just affect this one.

"Create group block". --- This will merge and select both leaves.

"Loop" block to repeat the copy an rotate action of the opposites leaves. We have to rotate each pair of leaves 15 degrees eleven times.

NOW YOU KNOW HOW TO COPY SHAPES.

Is just matter of adding a brown cylinder of 35 mm radius to complete the flower. ----Check sixth image.

## Step 2: The Math Behind the Golden Ratio.

First, please take a time to check this excellent video of Numberphile in Youtube, where they explain the math behind the golden ratio:

The whole video is a beautiful mathematical explanation of the geometry of rational an irrational numbers expressed in nodes and rotations. In the minute 6:28 to 6:45 it shows how the golden ratio best represents the seed arrangement in a sunflower.

So how do we simulate this in Tinkercad Codeblocks?

In the video they explain the numerical value of Phi between the minute 10:14 and 12:00. So, how can we compute it with codeblocks?

The first thing is the square root of 5. In the "Math" block menu (green), there is a block that has a "Sin" of 0 as a default. If you click in the dropdown menu the "Sin" can be changed to "square root" and you change the zero for a 5.

There is another block with two slots and a dropdown menu with a math operation between them. We type "1" in the first slot, choose math as the operation and then insert the Square root of five block we just made in the second slot.

For the division, we use the same type of block as the previous one. But in the first slot we insert the one we just built, in the middle we have to choose the division and in the second slot we type a 2.

We have Phi expressed with blocks. But in codeblock we can rotate with a giving angle, so we have to transform Phi in terms of angles. That is why we have to set some variables:

Radio: is the ratio. It can be Phi, Pi or any other rational number, like square root of two. We use this to be able to change the value of the ratio between any rational or irrational number we want to simulate.

Angulo: is the angle. We use this angle to rotate any new seed according to the chosen ratio (Radio variable).

To write this in codeblocks we use the "set" block in the "math" block menu (green). "Set" block will create and assign a given value to the variable we just created. --- Check the first image.

## Step 3: Seeds Distribution

This part is simple, we have to repeat three steps:

Adding a sphere as a seed (of radius of two).

Moving that seed away from the center a certain distance. This distance gets bigger as the number of seeds increases. So we can link the counter variable in the loop to this distance. In this case the counter is divided by 5 to put the seeds close enough to each other.

Rotating the seed according to the angle. This angle also gets bigger as the number of seeds increases. We linked this angle to the counter variable in the loop as well. The rotation axis is Z as we did with the leaves.

This way we just choose the "count with" block from the "control" block menu (orange) and we set the counter variable "i" from 1 to 150.

NOTE: The maximum amount of block that you can use in just one Codeblock is 200. Since we used some to create the flowers, that is why we can only create 150 seeds.

But its enough to simulate a sunflower, and the result is awesome, as the real sunflower is. --- Check the second image.

With this done, some question are inevitable:

Do plants do math?

Why is this constant everywhere in nature?

What is mathematics and why is it able to describe nature so well?

## Step 4: Additional Work

We can set irrational numbers with a fraction approximation. With a small web search we can find the most famous famous constants related to math and nature. Please check the image and use the irrational numbers to see what other pattern of seeds distribution you can achieve, and why the golden ratio is the best over all. Use this approximations to set the Radio variable.

To overcome the 200 blocks overflow, I ran the code three times with a set "Radio" (irrational number) with a different ranges (0 to 150, 151 to 300, 301 to 450) and took pictures of every result. Then used power point to remove the background of the seeds and overlap them. That gave me the opportunity to watch the distribution in a wider range. The resulting four images are shown (Euler, square root of two, Ln2 and Feigembaum constant).

Just for fun, you can check what can you say about a given irrational number comparing its numerical value to the hypothetical seed distribution.

## Step 5: Just for Fun.

No that you can use Codeblocks, you can challenge yourself to simulate other plants or organisms that shows a constant pattern like the golden ratio.

Runner Up in the

Block Code Contest

## 5 Comments

5 months ago

This is so cool! And its amazing for a first instructable! Great job!

Reply 4 months ago

Thank you so much!

5 months ago

This is amazing!

5 months ago

This is awesome! Thank you for sharing.

Reply 5 months ago

Thank you. This is my first instructable.