Wolfram Research

Function Repository Resource:

PolygonalDiagram

Source Notebook

Show an array of polygonal numbers

Contributed by: Eric W. Weisstein

ResourceFunction["PolygonalDiagram"][n,m]

gives a regular polygon of n sides with m levels of numbers arranged in equally spaced points.

Details and Options

A polygonal number is an array of n successive natural numbers that can be arranged in a triangle, square, etc. for some values of n, depending on the sides of the polygon. In general, any n-gonal number is equal to the sum of the (n - 1)-gonal number of the same rank and the triangular number of the previous rank.

Examples

Basic Examples

Get a diagram with a triangle with four levels:

In[1]:=
ResourceFunction["PolygonalDiagram"][3, 4]
Out[1]=

First five polygonal numbers and their diagrams:

In[2]:=
Table[PolygonalNumber[n], {n, 5}]
Out[2]=
In[3]:=
GraphicsRow[Table[ResourceFunction["PolygonalDiagram"][3, n], {n, 5}]]
Out[3]=

Options

PlotLabel

Add a PlotLabel to the diagram:

In[4]:=
ResourceFunction["PolygonalDiagram"][3, 4, PlotLabel -> Automatic]
Out[4]=

Applications

Add polygonal numbers:

In[5]:=
With[{k = 6, n = 5}, Text[Style[
   Row[{Row[{ResourceFunction["PolygonalDiagram"][3, k - 1, ImageSize -> {150, 150}, PlotLabel -> Automatic] /. Hue[_] -> Green, ResourceFunction["PolygonalDiagram"][n - 1, k, PlotLabel -> Automatic, ImageSize -> {150, 150}] /. Hue[_] -> Red}, "+"], MapAt[{Green, #1} &, ResourceFunction["PolygonalDiagram"][n, k, PlotLabel -> Automatic, ImageSize -> {150, 150}] /. Hue[_] -> Red, Flatten[Table[{1, 3, i, 2, j}, {i, k}, {j, i - 1}], 1]]}, "="], 18]]]
Out[5]=

Requirements

Wolfram Language 11.3 (March 2018) or above

Resource History

License Information