[Math] How many triangles in picture? Formula or algorithm for this

geometrypuzzlerecreational-mathematics

enter image description here

How many triangles are in this picture?
Is there any formula or computer software to calculate this?

Also: I know programming so I can program something to solve this if someone can point out an algorithm for this.

Best Answer

Here's a simple but tedious algorithm for you: Label the vertices $A, B, C, \ldots, N$. Now go through all triples in alphabetical order (thus $ABC, ABD, ABE, \ldots, LMN$) and check whether they form a triangle.

To improve this somewhat, take advantage of the symmetry. There are four vertices on the central axis; call them $A,B,C,D$. The others come in pairs: $E_1, E_2, F_1, F_2, \ldots, I_1, I_2$. Count the triangles that do not have vertical symmetry, and multiply by two. Then add to this count the triangles that do have vertical symmetry.