can someone help me generate code to type the diagram for any given natural number based on its prime factorization such as these diagrams
consider the next number 36 and its prime factorization, $36=3^2\cdot 2^2$, writing the primes in descending order… then, start with the pattern for a 3, which is 3 circles 120 degrees apart, now, replace each circle with 3 more circles in the same pattern to account for the $3^2$, this part would look like the pattern for 9 which is also $3^2$. now.. to finish the pattern for 36, we take the pattern for 9 and in each circle replace it with the pattern for 4… that is each of the 9 circles gets replaced with 4 tinier circles arranged in the same pattern as the pattern for 4
Best Answer
(See update at the end for an alternative output)
Done with Lualatex and tikz, simply converting the code from this javascript fiddle
This is a sample result for number 36:
Which was generated with:
The macro
\primediagram
receives four parameters. The first one is the number to represent. The remaining three are the center and radius of the diagram to be generated.A more interesting example:
Produced by a tikz loop:
The complete code
To produce these figures, three files are required:
primediagram.sty
This one simply defines the tex macro which interfaces with the lua code:
primediagram.lua
This one contains the lua code which actually performs the computations and outputs the required
\draw
commands for tikz. It is a direct translation to lua of the mentioned javascript code.The main document
You only need to include the
sty
package, as for example:Which produces the figure already shown.
Update: Rotating sub-groups
If each sub-groups is rotated according to the angle at which it is drawn, the output is different, nicer, and more close to the one shown by the OP. I also removed the black filling of the dots:
This is the new code (only
primediagram.lua
has to be replaced):