Created
March 28, 2022 15:58
-
-
Save CodeDrome/d99e188444877c5b6278d8a269b008cf to your computer and use it in GitHub Desktop.
bretschneidersformulamain.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from functools import reduce | |
import math | |
def calculate_area(sides, opposite_angles_degrees): | |
''' | |
Calculate the area of a quadrilateral using Bretschneider's Formula | |
from the lengths of the sides and either pair of OPPOSITE angles. | |
Arguments:- | |
sides - list in format [a,b,c,d] | |
opposite_angles_degrees - list in format [a1,a2] | |
''' | |
semiperimeter = sum(sides) / 2 | |
product_semiperimeter_minus_sides = (semiperimeter - sides[0]) * \ | |
(semiperimeter - sides[1]) * \ | |
(semiperimeter - sides[2]) * \ | |
(semiperimeter - sides[3]) | |
product_sides = reduce((lambda x, y: x * y), sides) | |
sum_of_radians = math.radians(opposite_angles_degrees[0]) + math.radians(opposite_angles_degrees[1]) | |
cos_squared = ( math.cos(sum_of_radians / 2 ) ) **2 | |
area = math.sqrt(product_semiperimeter_minus_sides - product_sides * cos_squared) | |
return area |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment