Just as any polygon can be considered a set of triangles, any polygonal number can be generated from triangular numbers.

Consider a square number, and two triangular numbers of the same degree:

*--*--*--*
*--*--*--* *--*--*--* \ | | |
| | | | |\ | | | * \| | |
| | | | | \| | | |\ * * *
*--* * * *--* * * | \ \ | |
| | | | \ | | *--* \| |
| | | | \| | | \ * *
*--*--* * *--*--* * | \ \ |
| | | \ | *--*--* \|
| | | \| | \ *
*--*--*--* *--*--*--* | \
*--*--*--*

It is clear to see that two triangular numbers will have the same number of

dots, except the

diagonal gets counted twice. The

`r`th square number (

`p`^{4}_{r}) is twice the

`r`th triangular number (

`p`^{3}_{r}) minus

`r`. Consider

pentagonal numbers:

* *
* * /| |\
/ \ /|\ / | * | \
/ \ / | \ * | | | *
* * * | | * / \| | |/ \
/ \ / \ / \| |/ \ / * | | * \
/ *-* \ / *-* \ * | | | | *
* * * | | * / \ | *-* | / \
/ \ / \ / \ | | / \ / * | | | | * \
/ * * \ / * | | * \ * \| | | |/ *
* \ / * * \| |/ * \ * | | * /
\ *-*-* / \ *-*-* / * | | | | *
* * * | | * \ | *-*-* | /
\ / \ | | / * | | | | *
* * * | | * \| | | |/
\ / \| |/ * | | *
*-*-*-* *-*-*-* | |
*-*-*-*

Three triangles, with two diagonals counted twice, make a pentagon, so

`p`^{5}_{r} = (3 *

`p`^{3}_{r}) - (2 *

`r`).

An `n`-gonal number of degree `r`, by generalisation, is `p`^{n}_{r} = ((`n` - 2) * `p`^{3}_{r}) - ((`n` - 3) * `r`), and `p`^{3}_{r} = ((`r` + 1) * `r`) / 2.