TExcelTAD
Home › Pre-Calculus, Geometry & Trigonometry › Oblique Triangles: Laws of Sines and Cosines

Oblique Triangles: Laws of Sines and Cosines

Most triangles have no right angle. Such triangles are called oblique, and SOH-CAH-TOA alone cannot solve them. Two laws, the law of sines and the law of cosines, solve every triangle from three suitable pieces of information.

Notation

Label the angles A,B,CA, B, C and the sides opposite them a,b,ca, b, c. So side aa is across from angle AA, and so on. The angles always add to 180° (π\pi).

The law of sines

asin⁡A=bsin⁡B=csin⁡C\frac{a}{\sin A} = \frac{b}{\sin B} = \frac{c}{\sin C}

Why it is true. Drop the height hh from CC onto side cc. The two right triangles you get share hh:

h=b⋅sin⁡A(in the triangle containing A)h=a⋅sin⁡B(in the triangle containing B)⇒bsin⁡A=asin⁡B⇒asin⁡A=bsin⁡B\begin{aligned} h &= b \cdot \sin A && (\text{in the triangle containing } A) \\ h &= a \cdot \sin B && (\text{in the triangle containing } B) \\ &\Rightarrow b\sin A = a\sin B \quad\Rightarrow\quad \frac{a}{\sin A} = \frac{b}{\sin B} \end{aligned}

Dropping a height from another vertex brings in cc the same way. (If the height falls outside the triangle, the same algebra works with sin⁡(180∘−B)=sin⁡B\sin(180^\circ - B) = \sin B.) The common value is in fact the diameter 2R2R of the circle through the three vertices.

Use the law of sines when you know an angle and its opposite side, plus one more piece: AAS, ASA, or SSA.

The law of cosines

c2=a2+b2−2abcos⁡C(and likewise a2=b2+c2−2bccos⁡A, b2=a2+c2−2accos⁡B)\begin{aligned} &c^2 = a^2 + b^2 - 2ab\cos C \\ &(\text{and likewise } a^2 = b^2 + c^2 - 2bc\cos A,\ b^2 = a^2 + c^2 - 2ac\cos B) \end{aligned}

When C=90∘C = 90^\circ, cos⁡C=0\cos C = 0 and this is Pythagoras' theorem, so the law of cosines is Pythagoras with a correction term. Proof with coordinates: put CC at the origin, BB at (a,0)(a, 0) and AA at (bcos⁡C,bsin⁡C)(b\cos C, b\sin C). Then

c2=∣AB∣2=(bcos⁡C−a)2+(bsin⁡C)2=b2cos⁡2C−2abcos⁡C+a2+b2sin⁡2C=a2+b2−2abcos⁡C\begin{aligned} c^2 = \lvert AB \rvert^2 &= (b\cos C - a)^2 + (b\sin C)^2 \\ &= b^2\cos^2 C - 2ab\cos C + a^2 + b^2\sin^2 C \\ &= a^2 + b^2 - 2ab\cos C \end{aligned}

Use it for SAS (two sides and the angle between them) and SSS (three sides). Solved for the angle:

cos⁡C=a2+b2−c22ab\cos C = \frac{a^2 + b^2 - c^2}{2ab}

Solving triangles in code

python · try it yourself
import math

def solve_sas(a, b, C_deg):
    C = math.radians(C_deg)
    c = math.sqrt(a*a + b*b - 2*a*b*math.cos(C))
    A = math.degrees(math.acos((b*b + c*c - a*a) / (2*b*c)))
    return c, A, 180 - C_deg - A

def solve_sss(a, b, c):
    A = math.degrees(math.acos((b*b + c*c - a*a) / (2*b*c)))
    B = math.degrees(math.acos((a*a + c*c - b*b) / (2*a*c)))
    return A, B, 180 - A - B

c, A, B = solve_sas(8, 11, 47)
print(f"SAS a=8, b=11, C=47°: c = {c:.4f}, A = {A:.3f}°, B = {B:.3f}°")
print("SSS 4, 5, 6: angles =", [round(x, 3) for x in solve_sss(4, 5, 6)])
print("check law of sines:", round(8 / math.sin(math.radians(A)), 6), round(c / math.sin(math.radians(47)), 6))
SAS a=8, b=11, C=47°: c = 8.0603, A = 46.542°, B = 86.458°
SSS 4, 5, 6: angles = [41.41, 55.771, 82.819]
check law of sines: 11.021057 11.021057

Getting AA from acos rather than from the law of sines is deliberate: acos returns angles up to 180°, so it never picks the wrong one of two possible angles. asin returns at most 90°, which leads to the next topic.

The ambiguous case (SSA)

Given two sides and an angle not between them, there may be zero, one or two triangles. The law of sines gives sin⁡B\sin B, and both BB and 180∘−B180^\circ - B have that sine. Each candidate is valid if the angles still add to less than 180°.

python · try it yourself
import math

def solve_ssa(a, b, A_deg):
    """Known: side a, side b and angle A opposite a. Returns all triangles."""
    s = b * math.sin(math.radians(A_deg)) / a
    if s > 1:
        return []
    sols = []
    for B in {math.degrees(math.asin(s)), 180 - math.degrees(math.asin(s))}:
        C = 180 - A_deg - B
        if C > 1e-9:
            c = a * math.sin(math.radians(C)) / math.sin(math.radians(A_deg))
            sols.append((round(B, 3), round(C, 3), round(c, 4)))
    return sorted(sols)

print("a=7,  b=10, A=35°:", solve_ssa(7, 10, 35))
print("a=12, b=10, A=35°:", solve_ssa(12, 10, 35))
print("a=4,  b=10, A=35°:", solve_ssa(4, 10, 35))
a=7,  b=10, A=35°: [(55.024, 89.976, 12.2041), (124.976, 20.024, 4.1789)]
a=12, b=10, A=35°: [(28.554, 116.446, 18.732)]
a=4,  b=10, A=35°: []

With a=7a = 7 the side can swing to two positions; with a=12a = 12 the second candidate would make the angles add to more than 180°; with a=4a = 4 the side is too short to reach.

Area of any triangle

Area=12absin⁡C(two sides and the included angle)Area=s(s−a)(s−b)(s−c),s=a+b+c2(Heron’s formula, three sides)\begin{aligned} \text{Area} &= \tfrac{1}{2} ab\sin C && \text{(two sides and the included angle)} \\ \text{Area} &= \sqrt{s(s - a)(s - b)(s - c)}, \quad s = \frac{a + b + c}{2} && \text{(Heron's formula, three sides)} \end{aligned}

The first follows from area=12⋅base⋅height\text{area} = \tfrac{1}{2} \cdot \text{base} \cdot \text{height} with height bsin⁡Cb\sin C. For the 4-5-6 triangle, s=7.5s = 7.5 and the area is 7.5⋅3.5⋅2.5⋅1.5=98.4375≈9.9216\sqrt{7.5 \cdot 3.5 \cdot 2.5 \cdot 1.5} = \sqrt{98.4375} \approx 9.9216.

In software

  • Angle between two vectors. Put vectors uu and vv tail to tail. The third side is u−vu - v, and the law of cosines gives ∣u−v∣2=∣u∣2+∣v∣2−2∣u∣∣v∣cos⁡θ\lvert u - v \rvert^2 = \lvert u \rvert^2 + \lvert v \rvert^2 - 2\lvert u \rvert \lvert v \rvert\cos\theta. Expanding the left side with dot products leaves u⋅v=∣u∣∣v∣cos⁡θu \cdot v = \lvert u \rvert \lvert v \rvert\cos\theta, the formula every game engine and every embedding search uses (angle between vectors, the dot product).
  • Triangulation. Two sensors a known distance apart each measure the angle to a target; the law of sines gives the distances, so you get a position. Surveyors, old radio direction finders and stereo depth cameras work this way.
  • Inverse kinematics. A two-bone arm (upper arm, forearm) that must reach a target at distance dd: the law of cosines gives the elbow angle directly.
python · try it yourself
import math

# Two stations 10 km apart on the x-axis see a ship at interior angles 50° and 60°.
base, A, B = 10.0, math.radians(50), math.radians(60)
C = math.pi - A - B
dist_A = base * math.sin(B) / math.sin(C)          # law of sines: side opposite B
ship = (dist_A * math.cos(A), dist_A * math.sin(A))
print(f"distance from station A: {dist_A:.4f} km")
print(f"ship at ({ship[0]:.4f}, {ship[1]:.4f}) km")

# Two-bone IK: elbow angle for bones 3 and 2 reaching a target 4 away
L1, L2, d = 3.0, 2.0, 4.0
elbow = math.degrees(math.acos((L1**2 + L2**2 - d**2) / (2 * L1 * L2)))
print(f"elbow interior angle: {elbow:.3f}°")
distance from station A: 9.2160 km
ship at (5.9240, 7.0599) km
elbow interior angle: 104.478°

Exercises

Exercise 1: ASA

In a triangle, A=40∘A = 40^\circ, B=75∘B = 75^\circ and c=12c = 12. Find CC, aa and bb.

Answer

C=65∘C = 65^\circ, a≈8.511a \approx 8.511, b≈12.789b \approx 12.789.

Solution
C=180−40−75=65∘a=c⋅sin⁡A/sin⁡C=12⋅sin⁡40∘/sin⁡65∘b=c⋅sin⁡B/sin⁡C=12⋅sin⁡75∘/sin⁡65∘\begin{aligned} C &= 180 - 40 - 75 = 65^\circ \\ a &= c \cdot \sin A / \sin C = 12 \cdot \sin 40^\circ / \sin 65^\circ \\ b &= c \cdot \sin B / \sin C = 12 \cdot \sin 75^\circ / \sin 65^\circ \end{aligned}
python · try it yourself
import math
s = lambda d: math.sin(math.radians(d))
print(round(12 * s(40) / s(65), 3), round(12 * s(75) / s(65), 3))
8.511 12.789

Exercise 2: SSS

A triangle has sides 7, 8 and 13. Find its largest angle exactly.

Answer

120°.

Solution

The largest angle is opposite the longest side, 13:

cos⁡C=72+82−1322⋅7⋅8=49+64−169112=−56112=−12C=120∘\begin{aligned} \cos C &= \frac{7^2 + 8^2 - 13^2}{2 \cdot 7 \cdot 8} = \frac{49 + 64 - 169}{112} = -\frac{56}{112} = -\frac{1}{2} \\ C &= 120^\circ \end{aligned}

Exercise 3: How many triangles?

Given a=9a = 9, b=12b = 12 and A=40∘A = 40^\circ, how many triangles exist? Find the possible values of BB.

Answer

Two: B≈58.99∘B \approx 58.99^\circ or B≈121.01∘B \approx 121.01^\circ.

Solution
sin⁡B=12⋅sin⁡40∘/9≈0.857B≈58.99∘orB≈180−58.99=121.01∘Both leave room: 40+121.01=161.01<180, so two triangles.\begin{aligned} &\sin B = 12 \cdot \sin 40^\circ / 9 \approx 0.857 \\ &B \approx 58.99^\circ \quad\text{or}\quad B \approx 180 - 58.99 = 121.01^\circ \\ &\text{Both leave room: } 40 + 121.01 = 161.01 < 180, \text{ so two triangles.} \end{aligned}
python · try it yourself
import math
s = 12 * math.sin(math.radians(40)) / 9
B1 = math.degrees(math.asin(s))
print(round(s, 4), round(B1, 2), round(180 - B1, 2))
0.8571 58.99 121.01

Exercise 4: Area two ways

Find the area of the triangle with sides 7, 8, 13 using Heron's formula, and again with 12absin⁡C\tfrac{1}{2}ab\sin C using the angle from Exercise 2.

Answer

143≈24.24914\sqrt{3} \approx 24.249 both ways.

Solution
s=(7+8+13)/2=14Heron: 14⋅7⋅6⋅1=588=143≈24.24912⋅7⋅8⋅sin⁡120∘=28⋅32=143\begin{aligned} &s = (7 + 8 + 13)/2 = 14 \\ &\text{Heron: } \sqrt{14 \cdot 7 \cdot 6 \cdot 1} = \sqrt{588} = 14\sqrt{3} \approx 24.249 \\ &\tfrac{1}{2} \cdot 7 \cdot 8 \cdot \sin 120^\circ = 28 \cdot \frac{\sqrt{3}}{2} = 14\sqrt{3} \end{aligned}

Exercise 5: Angle between vectors

Use the law of cosines (not a dot product function) to find the angle between u=(3,1)u = (3, 1) and v=(1,4)v = (1, 4), then confirm with math.atan2.

Answer

About 57.53°.

Solution

The triangle has sides ∣u∣=10\lvert u \rvert = \sqrt{10}, ∣v∣=17\lvert v \rvert = \sqrt{17} and ∣u−v∣=∣(2,−3)∣=13\lvert u - v \rvert = \lvert (2, -3) \rvert = \sqrt{13}.

cos⁡θ=10+17−13210⋅17=142170≈0.5369⇒θ≈57.53∘\cos\theta = \frac{10 + 17 - 13}{2\sqrt{10} \cdot \sqrt{17}} = \frac{14}{2\sqrt{170}} \approx 0.5369 \quad\Rightarrow\quad \theta \approx 57.53^\circ
python · try it yourself
import math
u, v = (3, 1), (1, 4)
a, b = math.hypot(*u), math.hypot(*v)
c = math.hypot(u[0] - v[0], u[1] - v[1])
theta = math.degrees(math.acos((a*a + b*b - c*c) / (2*a*b)))
check = math.degrees(math.atan2(v[1], v[0]) - math.atan2(u[1], u[0]))
print(round(theta, 2), round(check, 2))
57.53 57.53

Test yourself

You know two sides and the angle between them. Which law do you start with?

  1. Law of sines
  2. Law of cosines
  3. Pythagoras
  4. Either; it makes no difference

What does the law of cosines reduce to when C=90∘C = 90^\circ?

  1. The law of sines
  2. c=a+bc = a + b
  3. c2=a2+b2c^2 = a^2 + b^2
  4. Nothing; it does not apply

Why is SSA called the ambiguous case?

  1. Because the law of cosines fails
  2. Because sin⁡B=k\sin B = k has two solutions between 0° and 180°, so there can be 0, 1 or 2 triangles
  3. Because the angles can add to more than 180°
  4. Because the sides must be equal