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
rth square number (
p4r) is twice the
rth triangular number (
p3r) minus
r. Consider
pentagonal numbers:
* *
* * /| |\
/ \ /|\ / | * | \
/ \ / | \ * | | | *
* * * | | * / \| | |/ \
/ \ / \ / \| |/ \ / * | | * \
/ *-* \ / *-* \ * | | | | *
* * * | | * / \ | *-* | / \
/ \ / \ / \ | | / \ / * | | | | * \
/ * * \ / * | | * \ * \| | | |/ *
* \ / * * \| |/ * \ * | | * /
\ *-*-* / \ *-*-* / * | | | | *
* * * | | * \ | *-*-* | /
\ / \ | | / * | | | | *
* * * | | * \| | | |/
\ / \| |/ * | | *
*-*-*-* *-*-*-* | |
*-*-*-*
Three triangles, with two diagonals counted twice, make a pentagon, so
p5r = (3 *
p3r) - (2 *
r).
An n-gonal number of degree r, by generalisation, is pnr = ((n - 2) * p3r) - ((n - 3) * r), and p3r = ((r + 1) * r) / 2.