From 0ab5f46c93e9f8d6e9491d4919fcfd2ccc9b4d6b Mon Sep 17 00:00:00 2001 From: Deepta Date: Sat, 10 Jan 2026 14:15:07 +0600 Subject: [PATCH 1/2] Added area_triangle_two_sides_included_angle function This adds yet another way to calculate the area of triagnle, in this case using the length of two sides and their included angle. --- maths/area.py | 46 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/maths/area.py b/maths/area.py index 31a654206977..cc439b21f696 100644 --- a/maths/area.py +++ b/maths/area.py @@ -3,7 +3,7 @@ Wikipedia reference: https://en.wikipedia.org/wiki/Area """ -from math import pi, sqrt, tan +from math import pi, sin, sqrt, tan def surface_area_cube(side_length: float) -> float: @@ -312,6 +312,50 @@ def area_triangle(base: float, height: float) -> float: return (base * height) / 2 +def area_triangle_two_sides_included_angle( + side1: float, side2: float, included_angle_degrees: float +) -> float: + """ + Calculate the area of a triangle given the length of any two sides and + their included angle. + + >>> round(area_triangle_two_sides_included_angle(10, 10, 30), 1) + 25.0 + + >>> round(area_triangle_two_sides_included_angle(10, 10, -30), 1) + 25.0 + + >>> round(area_triangle_two_sides_included_angle(10, 10, 330), 1) + 25.0 + + >>> round(area_triangle_two_sides_included_angle(10, 10, 180), 1) + 0.0 + + >>> round(area_triangle_two_sides_included_angle(10, 10, 0), 1) + 0.0 + + >>> round(area_triangle_two_sides_included_angle(0, 10, 120), 1) + 0.0 + + >>> area_triangle_two_sides_included_angle(1, -1, 1) + Traceback (most recent call last): + ... + ValueError: area_triangle_two_sides_included_angle() only accepts \ + non-negative lengths + + >>> area_triangle_two_sides_included_angle(-1, 1, 1) + Traceback (most recent call last): + ... + ValueError: area_triangle_two_sides_included_angle() only accepts \ + non-negative lengths + """ + if side1 < 0 or side2 < 0: + raise ValueError( + "area_triangle_two_sides_included_angle() only accepts non-negative lengths" + ) + return 0.5 * side1 * side2 * abs(sin(included_angle_degrees * pi / 180)) + + def area_triangle_three_sides(side1: float, side2: float, side3: float) -> float: """ Calculate area of triangle when the length of 3 sides are known. From 1ff087d3f479f637c891b382585451903a71955a Mon Sep 17 00:00:00 2001 From: Deepta Date: Sat, 10 Jan 2026 14:46:19 +0600 Subject: [PATCH 2/2] fixed doc test errors: area_triangle_two_sides_included_angle --- maths/area.py | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/maths/area.py b/maths/area.py index cc439b21f696..f3b2ae0340e7 100644 --- a/maths/area.py +++ b/maths/area.py @@ -321,33 +321,24 @@ def area_triangle_two_sides_included_angle( >>> round(area_triangle_two_sides_included_angle(10, 10, 30), 1) 25.0 - >>> round(area_triangle_two_sides_included_angle(10, 10, -30), 1) 25.0 - >>> round(area_triangle_two_sides_included_angle(10, 10, 330), 1) 25.0 - >>> round(area_triangle_two_sides_included_angle(10, 10, 180), 1) 0.0 - >>> round(area_triangle_two_sides_included_angle(10, 10, 0), 1) 0.0 - >>> round(area_triangle_two_sides_included_angle(0, 10, 120), 1) 0.0 - >>> area_triangle_two_sides_included_angle(1, -1, 1) Traceback (most recent call last): ... - ValueError: area_triangle_two_sides_included_angle() only accepts \ - non-negative lengths - + ValueError: ... >>> area_triangle_two_sides_included_angle(-1, 1, 1) Traceback (most recent call last): ... - ValueError: area_triangle_two_sides_included_angle() only accepts \ - non-negative lengths + ValueError: ... """ if side1 < 0 or side2 < 0: raise ValueError(