Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@CodeDrome
Created March 28, 2022 15:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CodeDrome/d99e188444877c5b6278d8a269b008cf to your computer and use it in GitHub Desktop.
Save CodeDrome/d99e188444877c5b6278d8a269b008cf to your computer and use it in GitHub Desktop.
bretschneidersformulamain.py
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