# Get a triangle’s angles from the sides

Hint: For the SSS case, you are given the 3 sides a, b, and c, and need to find the corresponding angles α, β, and γ. To find α, for example, you solve the equation a^2==b^2+c^2-2b c Cos[α] for the variable α. There will be 2 outputs, and the positive output will be your solution.

Now use that solution to create the function α[a_,b_c,_]:= (the output you obtained)*180/π//N (multiplying by 180/\[DoubledPi] will convert the angle from radians to degrees and postfixing //N will give an approximation to the angle). Do the same for β and γ. (For β you will solve the equation b^2==a^2+c^2-2a c Cos[β] for β, and use a similar equation to solve for γ).

You can then create the function sss[a_,b_,c_]:={α[a,b,c], β[a,b,c], γ[a,b,c], a, b, c}] which has input the 3 sides and as output the 3 angles and the 3 sides. Check your work by doing Example 2.

this is the given hint my professor provided.

Reduce[a^2 == b^2 + c^2 - 2 b c Cos[α]]
a == -Sqrt[b^2 + c^2 - 2 b c Cos[α]] ||
a == Sqrt[b^2 + c^2 - 2 b c Cos[α]]
f[α[a_, b_, c_] :=
Sqrt[b^2 + c^2 - 2 b c Cos[α]]*180/π // N]
f[Null]


This is as far as I've got. I don't think I'm using the proper code.

• Note Mathematica has primitives like SSSTriangle which work with symbolic inputs: \$Assumptions = Thread[{a, b, c} > 0]; t = SSSTriangle[a, b, c]; Simplify[PolygonAngle[t] /. {Conjugate -> Identity, Abs -> Identity}] – flinty Dec 6 '20 at 14:48

You can use SSSTriangle and TriangleMeasurement with the property {"InteriorAngle", All}:

ClearAll[αβγ]

αβγ[a_, b_, c_] := TriangleMeasurement[SSSTriangle[a, b, c], {"InteriorAngle", All}]

αβγ[a, b, c]

{ArcCos[(-a^2 + b^2 + c^2)/(2 b c)],
ArcCos[(a^2 - b^2 + c^2)/(2 a c)],
ArcCos[(a^2 + b^2 - c^2)/(2 a b)]}

• I am surprised over and over again about your knowledge of special Mathematica functions! – Ulrich Neumann Dec 9 '20 at 7:28
• @Ulrich, thank you. Need those functions because "don't know much about analytical geometry":) – kglr Dec 9 '20 at 7:33

If we assume a triangle a,b,c ( counterclockwise) with opposite angles α,β,γ (as you did) knowing the law of cosines we have the list:

cosini[a_, b_, c_] := {
(a^2 - b^2 - c^2)/(2 b c),
(b^2 - a^2 - c^2)/(2 a c),
(c^2 - a^2 - b^2)/(2 a b )}

(* Cos[α], Cos[β], Cos[γ]} *)


For example, the angles of an equilateral triangle evaluate to:

cosini[1, 1, 1] // ArcCos

(* {(2 π)/3, (2 π)/3, (2 π)/3} *)

Reduce[{ a > 0 , b > 0 , c > 0, 0 < α < π ,
0 < β < π, 0 < γ < π,
a^2 == b^2 + c^2 - 2*b*c*Cos[α],
b^2 == c^2 + a^2 - 2*c*a*Cos[β] ,
c^2 == a^2 + b^2 -
2*a*b*Cos[γ] }, {α, β, γ}, Reals]// Simplify