Function Repository Resource:

TriangularSpiralPoints

Source Notebook

Get the coordinates of the points on a triangular spiral

Contributed by: George Beck

ResourceFunction["TriangularSpiralPoints"][n]

gives the list of coordinate pairs on an equilateral triangular spiral with n sides starting at the origin.

Details and Options

The list starts at the origin and goes (roughly) NW, SW, E and repeats.

Examples

Basic Examples (4) 

Here are the points on the first four legs of the spiral:

In[1]:=
ResourceFunction["TriangularSpiralPoints"][4]
Out[1]=

This shows the sequence of points in order for the first six sides:

In[2]:=
With[{s = ResourceFunction["TriangularSpiralPoints"][6]}, Graphics[{{Pink, PointSize[.03], Point[s]}, Arrow@Partition[s, 2, 1]}]]
Out[2]=

40 black sides with 20 red sides overlaid:

In[3]:=
Graphics[{Line@ResourceFunction["TriangularSpiralPoints"][40], Red, Line@ResourceFunction["TriangularSpiralPoints"][20]}]
Out[3]=

The number of points in the first n sides are one more than the triangular numbers:

In[4]:=
Length@ResourceFunction["TriangularSpiralPoints"]@# & /@ Range[0, 10]
Out[4]=
In[5]:=
Table[1 + 1/2 n (n + 1), {n, 0, 10}]
Out[5]=

Neat Examples (2) 

This finds the coordinate pairs that are a prime distance along the square spiral:

In[6]:=
UlamTriangularSpiralPoints[n_] := ResourceFunction["TriangularSpiralPoints"][n][[
   Select[Range[1 + 1/2 n (n + 1)], PrimeQ]
   ]]

The larger points correspond to the primes 2, 3, 5, 7, 11:

In[7]:=
With[{n = 4}, Graphics[{{LightGray, Line@ResourceFunction["TriangularSpiralPoints"]@n}, Point@ResourceFunction["TriangularSpiralPoints"]@n, PointSize[.08],
    Point@UlamTriangularSpiralPoints@n}, ImageSize -> 100]]
Out[7]=

About 12% of the numbers up to 11326 are prime:

In[8]:=
With[{n = 150}, 1 + 1/2 n (n + 1)]
Out[8]=
In[9]:=
PrimePi@%
Out[9]=

Here is a plot of the first 1369 primes:

In[10]:=
Graphics@Point@UlamTriangularSpiralPoints@150
Out[10]=

About 11% of the numbers up to 11326 are lucky:

In[11]:=
ResourceFunction["LuckyNumbers"]@11326 // Length
Out[11]=

This finds the coordinate pairs that are at lucky number distances along the triangular spiral:

In[12]:=
LuckyTriangularSpiralPoints[n_] := ResourceFunction["TriangularSpiralPoints"][n][[
   ResourceFunction["LuckyNumbers"][1 + 1/2 n (n + 1)]
   ]]

Here are the first 1248 lucky numbers plotted along the triangular spiral:

In[13]:=
Graphics@Point@LuckyTriangularSpiralPoints@150
Out[13]=

Publisher

George Beck

Requirements

Wolfram Language 11.3 (March 2018) or above

Version History

  • 1.0.0 – 26 February 2019

Related Resources

License Information