Python program to find angle between mid-point and base of a right angled triangle

When we have a right-angled triangle with sides AB and BC, we can find the angle between the midpoint M of the hypotenuse AC and the base BC using trigonometry. This angle can be calculated using the arctangent function.

A B C M ? BC AB AC

In this diagram, M is the midpoint of hypotenuse AC, and we need to find angle ? between line MB and base BC.

Mathematical Approach

The angle can be calculated using the arctangent function:

  • Calculate the ratio: AB/BC
  • Find the arctangent: arctan(AB/BC)
  • Convert the result from radians to degrees

Example

Let's implement this solution with proper input validation ?

import math

def find_angle(ab, bc):
    """Find angle between midpoint of hypotenuse and base in degrees"""
    if bc == 0:
        return 90.0  # Handle division by zero
    
    # Calculate angle using arctangent
    angle_radians = math.atan(ab / bc)
    
    # Convert to degrees
    angle_degrees = math.degrees(angle_radians)
    
    return angle_degrees

# Test with given values
ab = 6
bc = 4
result = find_angle(ab, bc)
print(f"Angle between midpoint and base: {result} degrees")
Angle between midpoint and base: 56.309932474020215 degrees

Step-by-Step Calculation

Let's break down the calculation process ?

import math

def detailed_calculation(ab, bc):
    print(f"Given: AB = {ab}, BC = {bc}")
    
    # Step 1: Calculate ratio
    ratio = ab / bc
    print(f"Step 1: Ratio AB/BC = {ratio}")
    
    # Step 2: Find arctangent in radians
    angle_rad = math.atan(ratio)
    print(f"Step 2: arctan({ratio}) = {angle_rad} radians")
    
    # Step 3: Convert to degrees
    angle_deg = math.degrees(angle_rad)
    print(f"Step 3: {angle_rad} radians = {angle_deg} degrees")
    
    return angle_deg

# Example calculation
ab = 6
bc = 4
result = detailed_calculation(ab, bc)
Given: AB = 6, BC = 4
Step 1: Ratio AB/BC = 1.5
Step 2: arctan(1.5) = 0.9827937232473292 radians
Step 3: 0.9827937232473292 radians = 56.309932474020215 degrees

Multiple Test Cases

Let's test with different triangle dimensions ?

import math

def find_angle(ab, bc):
    if bc == 0:
        return 90.0
    return math.degrees(math.atan(ab / bc))

# Test cases
test_cases = [
    (6, 4),    # Given example
    (3, 4),    # Common 3-4-5 triangle
    (4, 3),    # Swapped dimensions
    (5, 5),    # Equal sides (45 degrees expected)
    (1, 10)    # Small angle
]

print("AB\tBC\tAngle (degrees)")
print("-" * 30)
for ab, bc in test_cases:
    angle = find_angle(ab, bc)
    print(f"{ab}\t{bc}\t{angle:.2f}")
AB	BC	Angle (degrees)
------------------------------
6	4	56.31
3	4	36.87
4	3	53.13
5	5	45.00
1	10	5.71

Conclusion

To find the angle between the midpoint of a hypotenuse and the base of a right triangle, use the arctangent of the ratio AB/BC. The math.atan() function returns the angle in radians, which can be converted to degrees using math.degrees().

Updated on: 2026-03-26T15:38:03+05:30

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements