📜  计算平行四边形面积的程序

📅  最后修改于: 2021-10-23 08:09:45             🧑  作者: Mango

给定整数AB表示平行四边形和Y的边长 即平行四边形的对角线D1D2的边和长度之间的角度以及对角线相交处的角度0 ,任务是从提供的信息中找到平行四边形的面积。

例子:

方法:平行四边形的面积可以通过以下三个公式计算:

  • 由给定的边AB以及对角线之间的角度,平行四边形的面积可以通过以下公式计算:

  • 由给定的边AB以及边之间的角度,可以通过以下公式计算平行四边形的面积:

  • 由给定的对角线D1D2 的长度以及它们之间的角度,平行四边形的面积可以通过以下公式计算:

下面是上述方法的实现:

C++
// C++ program for the
// above approach
#include 
using namespace std;
 
double toRadians(int degree)
{
  double pi = 3.14159265359;
  return ((double)degree * (pi / 180));
}
 
// Function to return the area of
// parallelogram using sides and
// angle at the intersection of diagonal
double Area_Parallelogram1(int a, int b,
                           int theta)
{
  
    // Calculate area of parallelogram
    double area = (abs(tan(toRadians(theta))) / 2) *
                   abs(a * a - b * b);
  
    // Return the answer
    return area;
}
  
// Function to return the area of
// parallelogram using sides and
// angle at the intersection of sides
double Area_Parallelogram2(int a, int b,
                           int gamma)
{    
  // Calculate area of parallelogram
  double area = (abs(sin(toRadians(gamma)))) *
                 abs(a * b);
 
  // Return the answer
  return area;
}
  
// Function to return the area of
// parallelogram using diagonals and
// angle at the intersection of diagonals
static double Area_Parallelogram3(int d1, int d2,
                                  int theta)
{    
  // Calculate area of parallelogram
  double area = (abs(sin(toRadians(theta))) / 2) *
                 abs(d1 * d2);
 
  // Return the answer
  return area;
}
 
  
// Driver Code
int main()
{
  // Given diagonal and angle
  int d1 = 3;
  int d2 = 5;
  int theta = 90;
 
  // Function call
  double area = Area_Parallelogram3(d1,
                                    d2,
                                    theta);
   
  // Print the area
  printf("%.2f", area);
}
 
// This code is contributed by rutvik_56


Java
// Java program for above approach
import java.io.*;
 
class GFG{
 
// Function to return the area of
// parallelogram using sides and
// angle at the intersection of diagonal
static double Area_Parallelogram1(int a, int b,
                                  int theta)
{
 
    // Calculate area of parallelogram
    double area = (Math.abs(Math.tan(
                   Math.toRadians(theta))) / 2) *
                   Math.abs(a * a - b * b);
 
    // Return the answer
    return area;
}
 
// Function to return the area of
// parallelogram using sides and
// angle at the intersection of sides
static double Area_Parallelogram2(int a, int b,
                                  int gamma)
{
     
    // Calculate area of parallelogram
    double area = (Math.abs(Math.sin(
                   Math.toRadians(gamma)))) *
                   Math.abs(a * b);
 
    // Return the answer
    return area;
}
 
// Function to return the area of
// parallelogram using diagonals and
// angle at the intersection of diagonals
static double Area_Parallelogram3(int d1, int d2,
                                  int theta)
{
     
    // Calculate area of parallelogram
    double area = (Math.abs(Math.sin(
                   Math.toRadians(theta))) / 2) *
                   Math.abs(d1 * d2);
 
    // Return the answer
    return area;
}
 
// Driver code
public static void main (String[] args)
{
     
    // Given diagonal and angle
    int d1 = 3;
    int d2 = 5;
    int theta = 90;
     
    // Function call
    double area = Area_Parallelogram3(
                  d1, d2, theta);
     
    // Print the area
    System.out.format("%.2f", area);
}
}
 
// This code is contributed by offbeat


Python3
# Python3 program for the above approach
 
import math
 
# Function to return the area of
# parallelogram using sides and
# angle at the intersection of diagonal
def Area_Parallelogram1(a, b, theta):
 
    # Calculate area of parallelogram
    area = (abs(math.tan(math.radians(theta)))/2) \
           * abs(a**2 - b**2)
 
    # Return the answer
    return area
 
# Function to return the area of
# parallelogram using sides and
# angle at the intersection of sides
def Area_Parallelogram2(a, b, gamma):
 
    # Calculate area of parallelogram
    area = (abs(math.sin(math.radians(gamma)))) \
            * abs(a * b)
 
    # Return the answer
    return area
 
# Function to return the area of
# parallelogram using diagonals and
# angle at the intersection of diagonals
def Area_Parallelogram3(d1, d2, theta):
 
    # Calculate area of parallelogram
    area = (abs(math.sin(math.radians(theta)))/2) \
            * abs(d1 * d2)
 
    # Return the answer
    return area
 
 
# Driver Code
 
# Given diagonal and angle
d1 = 3
d2 = 5
theta = 90
 
# Function Call
area = Area_Parallelogram3(d1, d2, theta)
# Print the area
print(round(area, 2))


C#
// C# program for
// the above approach
using System;
class GFG{
 
// Function to return the area of
// parallelogram using sides and
// angle at the intersection of diagonal
static double Area_Parallelogram1(int a, int b,
                                  int theta)
{
  // Calculate area of parallelogram
  double area = (Math.Abs(Math.Tan((theta *
                          Math.PI) / 180)) / 2) *
                 Math.Abs(a * a - b * b);
 
  // Return the answer
  return area;
}
 
// Function to return the area of
// parallelogram using sides and
// angle at the intersection of sides
static double Area_Parallelogram2(int a, int b,
                                  int gamma)
{   
  // Calculate area of parallelogram
  double area = (Math.Abs(Math.Sin((gamma *
                          Math.PI) / 180))) *
                 Math.Abs(a * b);
 
  // Return the answer
  return area;
}
 
// Function to return the area of
// parallelogram using diagonals and
// angle at the intersection of diagonals
static double Area_Parallelogram3(int d1, int d2,
                                  int theta)
{   
  // Calculate area of parallelogram
  double area = (Math.Abs(Math.Sin((theta *
                          Math.PI) / 180)) / 2) *
                 Math.Abs(d1 * d2);
 
  // Return the answer
  return area;
}
 
// Driver code
public static void Main(String[] args)
{
  // Given diagonal and angle
  int d1 = 3;
  int d2 = 5;
  int theta = 90;
 
  // Function call
  double area = Area_Parallelogram3(d1, d2, theta);
 
  // Print the area
  Console.Write("{0:F2}", area);
}
}
 
// This code is contributed by Rajput-Ji


Javascript


输出:
7.5

时间复杂度: O(1)
辅助空间: O(1)

如果您希望与专家一起参加现场课程,请参阅DSA 现场工作专业课程学生竞争性编程现场课程