Solving Triangles
Standard notation
Sides \(a, b, c\) opposite angles \(A, B, C\). Angles sum to 180°:
Law of Sines
Use when you know two angles + any side (AAS, ASA) or two sides + a non-included angle (SSA, careful — ambiguous case below).
(\(R\) is the circumradius — the common ratio equals the diameter of the circumscribed circle.)
Example (AAS). \(A = 40°\), \(B = 70°\), \(a = 8\). Then \(C = 70°\), and:
import math
a = 8
b = a * math.sin(math.radians(70)) / math.sin(math.radians(40))
print(round(b, 2)) # 11.7Law of Cosines
Use for SSS (three sides → angles) or SAS (two sides + included angle → third side). It generalizes Pythagoras:
Cyclic versions hold for the other sides. When \(C = 90°\), \(\cos C = 0\) and you recover \(c^2 = a^2 + b^2\).
Example (SAS). \(a = 5\), \(b = 7\), \(C = 60°\):
Example (SSS → angle). Sides 3, 4, 5 — is it right? Solve for the angle opposite side 5:
Which law when?
| Known | Use |
|---|---|
| AAS, ASA | Law of Sines |
| SAS, SSS | Law of Cosines (then Sines for remaining) |
| SSA | Law of Sines, but check the ambiguous case (0, 1, or 2 triangles) |
| AAA | Nothing — similar triangles; angles alone never fix size |
Solver sketch:
import math
def law_of_cos_side(a, b, C_deg):
C = math.radians(C_deg)
return math.sqrt(a*a + b*b - 2*a*b*math.cos(C))
def law_of_sines_side(a, A_deg, B_deg):
return a * math.sin(math.radians(B_deg)) / math.sin(math.radians(A_deg))
def angle_from_sss(a, b, c):
# angle opposite side c
cosC = (a*a + b*b - c*c) / (2*a*b)
cosC = max(-1.0, min(1.0, cosC)) # clamp for float safety
return math.degrees(math.acos(cosC))
print(round(law_of_cos_side(5, 7, 60), 2)) # 6.24
print(round(angle_from_sss(3, 4, 5), 2)) # 90.0function lawOfCosSide(a, b, cDeg) {
const c = cDeg * Math.PI / 180;
return Math.sqrt(a*a + b*b - 2*a*b*Math.cos(c));
}
console.log(lawOfCosSide(5, 7, 60).toFixed(2)); // 6.24
Watch out
- Degree/radian mix-ups — convert before
sin/cos, convert back afterasin/acos. - SSA ambiguity — e.g. side-angle-side with the angle not included can yield two valid triangles. If your solver finds \(\sin B > 1\), no triangle exists; if \(\sin B\) gives \(B\) acute, \(180° − B\) may also work.
- Float clamp — always clamp
cosinputs to \([−1, 1]\) beforeacos, or rounding error throwsNaN/ValueError.
Practice
- Triangle: \(A = 50°\), \(B = 60°\), \(c = 10\) (side between them). Find \(C\) then sides \(a, b\).
- Sides 7, 8, 9. Find the largest angle. (Answer ≈ 73.4°.)
- Two GPS points form SAS: legs 3 km and 4 km with 90° between. How far apart are the endpoints? (Sanity: 3-4-5.)
- Code it: extend the solver above to take SSS and return all three angles; assert they sum to 180°.
Next: Graphs of Trig Functions — turning these values into waves.