Calculate the area of ​​a quadrangle

I am trying to create a calculator that calculates the area of ​​a simple quadrangle. I know that each quadrangle can be divided into two triangles, and I must be able to calculate the area in two parts no matter what. I can do this in math, but I don't know how to implement it in Python.

Here is my four sided class:

class Quadrilateral(Shape):
   def __init__(self, name):
       # in clockwise order: angles[0], sides[0], angles[1], sides[1], ...
       self.sides = [5] * 4
       self.angles = [90] * 4
       super().__init__(self, name)

Now I need to implement a method get_area()that calculates the area of ​​my quadrilateral, but I have no idea how to do this.

Here's how I would do it with paper and pen:

Area of ​​a quadrilateral

Basically, I would need to know only two angles and three sides in order to be able to use this technique to calculate the area, but don't worry about it. As long as I know all angles and all sides, how can I calculate the area?

+5
2

, :

import math

area1 = 0.5 * self.sides[0] * self.sides[1] * math.sin(math.radians(self.angles[1]))
area2 = 0.5 * self.sides[2] * self.sides[3] * math.sin(math.radians(self.angles[3]))
area = area1 + area2

sides = [3, 5, 5, 4] angles = [90, 95, 75, 100], :

>>> import math
>>> sides = [3, 5, 5, 4]
>>> angles = [90, 95, 75, 100]
>>> area1 = 0.5 * sides[0] * sides[1] * math.sin(math.radians(angles[1]))
>>> area2 = 0.5 * sides[2] * sides[3] * math.sin(math.radians(angles[3]))
>>> area1 + area2
17.31953776581017
+4

All Articles