The Law of cosines states that for an angle γ, (gamma) of any triangle, if the sides adjacent to the angle are A and B and the side opposite is C; then the lengths of the sides are related by this formula:

           A2 + B2 - 2ABcos(γ) = C2 

Specific angles

For an angle of of   90º   this becomes the more familiar "Pythagoras equation":

           A2 + B2  =  C2           

For an angle of   60º   this becomes the less familiar equation:

           A2 + B2 - AB  =  C2       

And finally for an angle of   120º   this becomes the equation:

           A2 + B2 + AB  =  C2      



Task

   Find all integer solutions (in order) to the three specific cases, distinguishing between each angle being considered.
   Restrain all sides to the integers   1..13   inclusive.
   Show how many results there are for each of the three angles mentioned above.
   Display results on this page.


Note: Triangles with the same length sides but different order are to be treated as the same.

Optional Extra credit

 How many 60° integer triples are there for sides in the range 1..10_000 where the sides are not all of the same length.


Related Task
 Pythagorean triples


See also

 Visualising Pythagoras: ultimate proofs and crazy contortions Mathlogger Video


' version 03-03-2019
' compile with: fbc -s console
 
#Define max 13
 
#Define Format(_x)  Right("    " + Str(_x), 4)
 
Dim As UInteger a, b, c, a2, b2, c2, c60 , c90, c120
Dim As String s60, s90, s120
 
For a = 1 To max
    a2 = a * a
    For b = a To max
        b2 = b * b
        ' 60 degrees
        c2 = a2 + b * b - a * b
        c = Sqr(c2)
        If c * c = c2 AndAlso c <= max Then
            s60 += Format(a) + Format(b) + Format(c) + Chr(10, 13)
            c60 += 1
        End If
        ' 90 degrees
        c2 = a2 + b * b
        c = Sqr(c2)
        If c * c = c2 AndAlso c <= max Then
            s90 += Format(a) + Format(b) + Format(c) + Chr(10, 13)
            c90 += 1
        End If
        ' 120 degrees
        c2 = a2 + b * b + a * b
        c = Sqr(c2)
        If c * c = c2 AndAlso c <= max Then
            s120 += Format(a) + Format(b) + Format(c) + Chr(10, 13)
            c120 += 1
        End If
    Next
Next
 
 
Print Using "###: 60 degree triangles"; c60
Print s60
Print
 
Print Using "###: 90 degree triangles"; c90
Print s90
Print
 
Print Using "###: 120 degree triangles"; c120
Print s120
Print
 
#Undef max
#Define max 10000
 
c60 = 0
For a = 1 To max
    a2 = a * a
    For b = a +1 To max
        c2 = a2 + b * (b - a)
        c = Sqr(c2)
        If c * c = c2 AndAlso c <= max Then
            c60 += 1
        End If
    Next
Next
 
Print "For 60 degree triangles in the range [1, 10000]"
Print "There are "; c60; " triangles that have different length for a, b and c"
 
' empty keyboard buffer
While InKey <> "" : Wend
Print : Print "hit any key to end program"
Sleep
End