# Systematically generate Corner and Centered polygonal diagrams?

A polygonal number is a number represented as dots or pebbles arranged in the shape of a regular polygon. Namely, it is "a type of figurate number which is a generalization of triangular, square, etc., numbers to an arbitrary n-gonal number".

The following diagrams taken from mathworld.wolfram.com graphically illustrate the process by which the polygonal numbers are built up. We can call them the Corner polygonal numbers, (i.e. growing from the dot in the corner). Each of the above types of numbers has a cousin of sorts, which is called the Centered polygonal numbers. There each formed by a central dot (See the below diagrams). Q: How to systematically generate the points (dots) arranged in the above Corner and Centered polygonal diagrams? Also the corresponding polygonal diagrams?

one simple example for certered square, i.e. n=4 (maybe one can directly create pts):

n = 4; (*3: triangle; 4: square; etc*)
pts =Flatten[Table[{r*Sin[2 Pi k/n], r*Cos[2 Pi k/n]}, {k, n}, {r, 0.1, 0.3, 0.1}], 1];
pts1={{0, 0}, {0.1, 0.1}, {0.1, 0.2}, {0.2, 0.1}, {-0.1, 0.1}, {-0.1, 0.2}, {-0.2, 0.1}, {0.1, -0.1}, {0.1, -0.2}, {0.2, -0.1}, {-0.1, -0.1}, {-0.1, -0.2}, {-0.2, -0.1}};
pts = Join[pts, pts1];
Graphics[{PointSize[Large], Point[pts]}]


## A very naïve approach

Let's use RegularPolygon (we could also use CirclePoints) with increasing radius. Then obtain its boundary and subdivide it.

subdivide[n_] :=
Line[{p1_, p2_}] :>
With[{pts = Table[p1 + i (p2 - p1), {i, 0, 1, 1/n}]}, pts];

centeredPolygon[p_, r_] :=
Join[MeshPrimitives[RegularPolygon[{r, 2 \[Pi]/p}, p], 1] /.
subdivide[r], {{{0, 0}}}];

corneredPolygon[p_, r_] :=
MeshPrimitives[RegularPolygon[{-r, 0}, {r, 2 \[Pi]/p}, p], 1] /.
subdivide[r];

GraphicsRow[
Table[Graphics[
Table[{Line[#], {PointSize[.05], Point[#]}} & /@
centeredPolygon[p, r], {r, 0, 4}]], {p, 3, 7}]]

GraphicsRow[
Table[Graphics[
Table[{Line[#], {PointSize[.05], Point[#]}} & /@
corneredPolygon[p, r], {r, 0, 4}]], {p, 3, 7}]]


### Centered Polygons ### Cornered Polygons • that's a very nice way to do it with RegularPolygon, thank you! Jul 30, 2021 at 6:34

Here's another approach using AnglePath:

cornerPath[n_, div_] := With[{s = Pi - (n-2)/(2n) Pi, a = Pi - (n-2)/n Pi},
AnglePath @ If[div==0,
Riffle[ConstantArray[0, n div], PadRight[{s}, n, a], {1, -2, div+1}]
]
]

centerPath[n_, div_] := TranslationTransform[{(div+1)/(2 Cos[(n-2)/(2n) Pi]), 0}] @ cornerPath[n, div]


Examples:

Graphics[{
PointSize[Large],
Table[Through @ {Point, Line} @ cornerPath[4, n], {n, 0, 3}]
}] Graphics[{
PointSize[Large],
Point[{0, 0}],
Table[Through @ {Point, Line} @ centerPath[5, n], {n, 0, 3}]
}] • thank you very much! that's very helpful Jul 30, 2021 at 6:21