Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Get the coordinates of the points on a hexagonal spiral
| ResourceFunction["HexagonalSpiralPoints"][n] gives the list of coordinate pairs on a hexagonal spiral with n sides starting with the origin. | 
Here are the points on the first four legs of the spiral:
| In[1]:= | ![ResourceFunction["HexagonalSpiralPoints"][4]](https://www.wolframcloud.com/obj/resourcesystem/images/fd7/fd7578f4-f1e2-4726-88a8-f5d904af77ce/6bc5528a34c95a8e.png) | 
| Out[1]= |  | 
This shows the sequence of points in order for six sides:
| In[2]:= | ![With[{s = ResourceFunction["HexagonalSpiralPoints"][6]}, Graphics[{{Pink, PointSize[.03], Point[s]}, Arrow@Partition[s, 2, 1]}]]](https://www.wolframcloud.com/obj/resourcesystem/images/fd7/fd7578f4-f1e2-4726-88a8-f5d904af77ce/31cfa1c10bd3100e.png) | 
| Out[2]= |  | 
40 black sides with 20 red sides overlaid:
| In[3]:= | ![Graphics[{Line@ResourceFunction["HexagonalSpiralPoints"][40], Red, Line@ResourceFunction["HexagonalSpiralPoints"][20]}]](https://www.wolframcloud.com/obj/resourcesystem/images/fd7/fd7578f4-f1e2-4726-88a8-f5d904af77ce/26c2ce5ec40b40b5.png) | 
| Out[3]= |  | 
The number of points in the first n sides:
| In[4]:= | ![Length@ResourceFunction["HexagonalSpiralPoints"]@# & /@ Range[0, 20]](https://www.wolframcloud.com/obj/resourcesystem/images/fd7/fd7578f4-f1e2-4726-88a8-f5d904af77ce/38d937d3153b8b3b.png) | 
| Out[4]= |  | 
| In[5]:= | ![Table[Round[(n + 3)^2/12], {n, 21}]](https://www.wolframcloud.com/obj/resourcesystem/images/fd7/fd7578f4-f1e2-4726-88a8-f5d904af77ce/4dbaf3cc4cc7f623.png) | 
| Out[5]= |  | 
This finds the coordinate pairs that are a prime distance counting along the square spiral:
| In[6]:= | ![UlamHexagonalSpiralPoints[n_] := ResourceFunction["HexagonalSpiralPoints"][n][[
   Select[Range[Round[(n + 4)^2/12]], PrimeQ]
   ]]](https://www.wolframcloud.com/obj/resourcesystem/images/fd7/fd7578f4-f1e2-4726-88a8-f5d904af77ce/31b704b4ab19465e.png) | 
The larger points correspond to the primes 2, 3, 5, 7, 11, 13:
| In[7]:= | ![With[{n = 9}, Graphics[{{LightGray, Line@ResourceFunction["HexagonalSpiralPoints"]@n}, Point@ResourceFunction["HexagonalSpiralPoints"]@n, PointSize[.08], Point@UlamHexagonalSpiralPoints@n}, ImageSize -> 100]]](https://www.wolframcloud.com/obj/resourcesystem/images/fd7/fd7578f4-f1e2-4726-88a8-f5d904af77ce/74269b86655371ba.png) | 
| Out[7]= |  | 
About 12% of the numbers up to 10443 are prime:
| In[8]:= | ![With[{n = 350}, Round[(n + 4)^2/12]]](https://www.wolframcloud.com/obj/resourcesystem/images/fd7/fd7578f4-f1e2-4726-88a8-f5d904af77ce/15c28da33864353f.png) | 
| Out[8]= |  | 
| In[9]:= |  | 
| Out[9]= |  | 
Here is a plot of the first 1277 primes:
| In[10]:= |  | 
| Out[10]= |  | 
About 11% of the numbers to 10443 are lucky:
| In[11]:= | ![ResourceFunction["LuckyNumbers"]@10443 // Length](https://www.wolframcloud.com/obj/resourcesystem/images/fd7/fd7578f4-f1e2-4726-88a8-f5d904af77ce/5721a043475b9c16.png) | 
| Out[11]= |  | 
This finds the coordinate pairs that are at lucky number distances along the hexagonal spiral:
| In[12]:= | ![LuckyHexagonalSpiralPoints[n_] := ResourceFunction["HexagonalSpiralPoints"][n][[
   ResourceFunction["LuckyNumbers"][Round[(n + 4)^2/12]]
   ]]](https://www.wolframcloud.com/obj/resourcesystem/images/fd7/fd7578f4-f1e2-4726-88a8-f5d904af77ce/74d0a66c26336ada.png) | 
Here are the first 1248 lucky numbers plotted along the hexagonal spiral:
| In[13]:= |  | 
| Out[13]= |  | 
Wolfram Language 11.3 (March 2018) or above
This work is licensed under a Creative Commons Attribution 4.0 International License