The field of geometry offers tools that have withstood the test of time, empowering us to understand and solve a variety of triangular problems. Among these, the Pythagorean Theorem and the Law of Cosines are cornerstone concepts. This article provides a step-by-step exploration of these mathematical principles, demonstrating how they are used to unravel the mysteries of triangles.
TLDR:
Pretty much, Pythagoras theorem states that c^2 = a^2 + b^2, but this one works only for right angle triangles. This is fixed, when we actually know the angle between the two sides and thus we can calculate it with the Cosinus Theorem = c^2 = a^2 + b^2 – 2*a*b*cos(c).
In the code below this is carried out. First we calculate the missing side and then we even plot it with Python.
1 2 3 4 |
import math import numpy as np import matplotlib.pyplot as plt |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
def calculate_third_side(a, b, angle_degrees): angle_radians = math.radians(angle_degrees) print(f"Step 1: Convert angle {angle_degrees} degrees to radians: {angle_radians:.4f} radians.") c_squared = a**2 + b**2 - 2*a*b*math.cos(angle_radians) print(f"Step 2: Compute c^2 using the formula: c^2 = {a}^2 + {b}^2 - 2 * {a} * {b} * cos({angle_radians:.4f})") print(f" => c^2 = {c_squared:.4f}") c = math.sqrt(c_squared) print(f"Step 3: Compute the square root of c^2: c = √{c_squared:.4f}") print(f" => c = {c:.2}") return c |
1 2 3 |
a = 5 b = 4 angle_c = 60 # in degrees |
1 |
calculate_third_side(a, b, angle_c) |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
def plot_triangle_fixed_angle(a, b, angle_degrees): angle_radians = np.radians(angle_degrees) # Coordinates of the triangle vertices A = (0, 0) # Starting point B = (a, 0) # Second point at a distance 'a' along the x-axis C = (b * np.cos(angle_radians), b * np.sin(angle_radians)) # Third point using angle and side 'b' # Plot the triangle plt.figure(figsize=(4, 4)) plt.plot([A[0], B[0]], [A[1], B[1]], 'bo-', label=f"Side a = {a}") plt.plot([C[0], A[0]], [C[1], A[1]], 'ro-', label=f"Side b = {b}") plt.plot([B[0], C[0]], [B[1], C[1]], 'go-', label="Side c") # Add annotations for vertices plt.text(A[0] - 0.5, A[1]- 0.5, "A (0, 0)", fontsize=10) plt.text(B[0] - 1, B[1]- 0.5, f"B ({B[0]:.1f}, {B[1]:.1f})", fontsize=10) plt.text(C[0] - 0.5, C[1] + 0.2, f"C ({C[0]:.1f}, {C[1]:.1f})", fontsize=10) angle_arc = np.linspace(0, angle_radians, 100) arc_radius = .5 # Adjust for size arc_x = arc_radius * np.cos(angle_arc) arc_y = arc_radius * np.sin(angle_arc) plt.plot(arc_x, arc_y, 'k--', linewidth=0.8) # Dashed line for the angle arc plt.text(0.8 * arc_radius, 0.3 * arc_radius, f"{angle_degrees}°", fontsize=10, color="blue") plt.xlim(-1, max(a, b) + 1) plt.ylim(-1, max(a, b) + 1) plt.axhline(0, color='black', linewidth=0.5, linestyle='--') plt.axvline(0, color='black', linewidth=0.5, linestyle='--') plt.gca().set_aspect('equal', adjustable='box') plt.title(f"Triangle with a={a}, b={b}, angle={angle_degrees}°") plt.legend() plt.grid() plt.show() |
The Jupyter Notebook with the code and the pdf is here: