Given four sides of a quadrilateral, the task is to get the maximum area of the given quadrilateral for the given four sides in python.
Quadrilateral:
In geometry, a quadrilateral is a closed shape formed by joining four points, any three of which are non-collinear. A quadrilateral is made up of four sides, four angles, and four vertices. The term ‘quadrilateral’ is derived from the Latin words ‘quadra’ (four) and ‘Latus’ (sides). A quadrilateral’s four sides may or may not be equal.
Formula:
The formula to calculate the maximum area of the given quadrilateral is :
This is known as Brahmagupta’s Formula.
s=(a+b+c+d)/2
where a, b, c, d are the four sides of a quadrilateral.
Examples:
Example1:
Input:
Given first side = 2 Given second side = 1 Given third side = 3 Given fourth side = 4
Output:
The maximimum area of quadrilateral for the given four sides { 2 , 1 , 3 , 4 } = 4.898979485566356Example2:
Input:
Given first side = 5 Given second side = 3 Given third side = 5 Given fourth side = 2
Output:
The maximimum area of quadrilateral for the given four sides { 5 , 3 , 5 , 2 } = 12.43734296383275Program for Maximum Area of Quadrilateral in Python
Below are the ways to get the maximum area of the given quadrilateral for the given four sides in python:
Method #1: Using Mathematical Formula (Static Input)
Approach:
- Import math module using the import keyword.
- Give the first side as static input and store it in a variable.
- Give the second side as static input and store it in another variable.
- Give the third side as static input and store it in another variable.
- Give the fourth side as static input and store it in another variable.
- Calculate the s value using the above given mathematical formula and store it in another variable.
- Calculate the maximum area of the given quadrilateral using the above given mathematical formula, math.sqrt() function and store it in another variable.
- Print the maximum area of the given quadrilateral.
- The Exit of the Program.
Below is the implementation:
# Import math module using the import keyword.
import math
# Give the first side as static input and store it in a variable.
p = 2
# Give the second side as static input and store it in another variable.
q = 1
# Give the third side as static input and store it in another variable.
r = 3
# Give the fourth side as static input and store it in another variable.
s = 4
# Calculate the s value using the above given mathematical formula andÂ
# store it in another variable.
s_valu = (p + q + r + s) / 2
# Calculate the maximum area of the given quadrilateral using the above
# given mathematical formula, math.sqrt() function and store it in another variable.
quadriltrlmax_area = math.sqrt(
(s_valu - p) * (s_valu - q) * (s_valu - r) * (s_valu - s))
# Print the maximum area of the given quadrilateral.
print(
"The maximimum area of quadrilateral for the given four sides {", p, ",", q, ",", r, ",", s, "} = ", quadriltrlmax_area)
# include <iostream>
# include<cmath>
using namespace std
int main() {
int p = 2
int q = 1
int r = 3
int s = 4
int s_valu = (p + q + r + s) / 2
double quadriltrlMaxArea = sqrt((s_valu - p) * (s_valu - q) * (s_valu - r) * (s_valu - s))
cout << "The maximimum area of quadrilateral for the given four sides {" << p << "," << q << "," << r << "," << s << "} = " << quadriltrlMaxArea << endl
return 0
}
Output:
The maximimum area of quadrilateral for the given four sides { 2 , 1 , 3 , 4 } = 4.898979485566356Method #2: Using Mathematical Formula (User Input)
Approach:
- Import math module using the import keyword.
- Give the first side as user input using the int(input()) function and store it in a variable.
- Give the second side as user input using the int(input()) function and store it in another variable.
- Give the third side as user input using the int(input()) function and store it in another variable.
- Give the fourth side as user input using the int(input()) function and store it in another variable.
- Calculate the s value using the above given mathematical formula and store it in another variable.
- Calculate the maximum area of the given quadrilateral using the above given mathematical formula, math.sqrt() function and store it in another variable.
- Print the maximum area of the given quadrilateral.
- The Exit of the Program.
Below is the implementation:
# Import math module using the import keyword.
import math
# Give the first side as user input using the int(input()) function and store it in a variable.
p = int(input("Enter some random number = "))
# Give the second side as user input using the int(input()) function and store it in another variable.
q = int(input("Enter some random number = "))
# Give the third side as user input using the int(input()) function and store it in another variable.
r = int(input("Enter some random number = "))
# Give the fourth side as user input using the int(input()) function and store it in another variable.
s = int(input("Enter some random number = "))
# Calculate the s value using the above given mathematical formula andÂ
# store it in another variable.
s_valu = (p + q + r + s) / 2
# Calculate the maximum area of the given quadrilateral using the above
# given mathematical formula, math.sqrt() function and store it in another variable.
quadriltrlmax_area = math.sqrt(
(s_valu - p) * (s_valu - q) * (s_valu - r) * (s_valu - s))
# Print the maximum area of the given quadrilateral.
print(
"The maximimum area of quadrilateral for the given four sides {", p, ",", q, ",", r, ",", s, "} = ", quadriltrlmax_area)
Output:
Enter some random number = 5
Enter some random number = 3
Enter some random number = 5
Enter some random number = 2
The maximimum area of quadrilateral for the given four sides { 5 , 3 , 5 , 2 } = 12.43734296383275Output:
