6
$\begingroup$

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).

Corner Polygonal Numbers

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).

Centred Polygonal Numbers

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]}]
$\endgroup$

2 Answers 2

9
$\begingroup$

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

Mathematica graphics

Cornered Polygons

Mathematica graphics

$\endgroup$
1
  • $\begingroup$ that's a very nice way to do it with RegularPolygon, thank you! $\endgroup$
    – Xuemei
    Jul 30, 2021 at 6:34
7
$\begingroup$

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,
        PadRight[{s}, n, a],
        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}]
}]

enter image description here

Graphics[{
    PointSize[Large],
    Point[{0, 0}], 
    Table[Through @ {Point, Line} @ centerPath[5, n], {n, 0, 3}]
}]

enter image description here

$\endgroup$
1
  • $\begingroup$ thank you very much! that's very helpful $\endgroup$
    – Xuemei
    Jul 30, 2021 at 6:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.