You can try to find the solutions manually but some of them are pretty hard to visualize. The example howto_find_equilateral_triangles uses the following code to find the solutions.
The code loops through all of the points three times. Each loop starts at the point after the point used in the enclosing loop so the innermost loop only considers each triple of points once and the points in each triple are unique. In other words, the code doesn't look at triples that contain a point more than once.
The code calculates the distances between the pairs of points in each triple and, if the distances are the same, adds a new triangle holding the points to the solution list.
Note that the distances are floating point values and rounding errors often make floating point values not exactly equal when they should be the same. This is a common problem when working with floating point numbers that should be the same. To avoid problems with equality testing, the code subtracts two distances, takes the absolute value, and checks whether the result is close to 0.
For example, when testing some of the points, the program finds these values that should be equal:
76.210235595703125
76.210235548698734
Subtracting them gives 0.000000047004391490190756, which is smaller than the value tiny defined by this code as 0.0001, so the program treats the two values as equal. (In fact, this example is measuring distances in pixels so you could define tiny to be 1 and you would still find the correct solutions.)
Seth Valdetero submitted a correct solution. Click here to download Seth's solution.
Comments