Find the area of rhombus from given Angle and Side length
Given two integers A and X, denoting the length of a side of a rhombus and an angle respectively, the task is to find the area of the rhombus.
A rhombus is a quadrilateral having 4 sides of equal length, in which both the opposite sides are parallel, and opposite angles are equal.
Examples:
Input: A = 4, X = 60
Output: 13.86
Input: A = 4, X = 30
Output: 8.0
Approach:For a Rhombus ABCD having the length of a side a and an angle x, the area of triangle ABD can be calculated using Side-Angle-Side property of triangle by the following equation:
Area of Triangle ABD = 1/2 (a2) sin x
Area of Rhombus ABCD will be double the area of ABD triangle.
Therefore, Area of Rhombus ABCD = (a2) sin x
Below is the implementation of the above approach:
C++
#include <bits/stdc++.h>
using namespace std;
#define RADIAN 0.01745329252
float Area_of_Rhombus( int a, int theta)
{
float area = (a * a) * sin ((RADIAN * theta));
return area;
}
int main()
{
int a = 4;
int theta = 60;
float ans = Area_of_Rhombus(a, theta);
printf ( "%0.2f" , ans);
return 0;
}
|
Java
class GFG{
static final double RADIAN = 0.01745329252 ;
static double Area_of_Rhombus( int a, int theta)
{
double area = (a * a) * Math.sin((RADIAN * theta));
return area;
}
public static void main(String[] args)
{
int a = 4 ;
int theta = 60 ;
double ans = Area_of_Rhombus(a, theta);
System.out.printf( "%.2f" , ans);
}
}
|
Python3
import math
def Area_of_Rhombus(a, theta):
area = (a * * 2 ) * math.sin(math.radians(theta))
return area
a = 4
theta = 60
ans = Area_of_Rhombus(a, theta)
print ( round (ans, 2 ))
|
C#
using System;
class GFG{
static readonly double RADIAN = 0.01745329252;
static double Area_of_Rhombus( int a, int theta)
{
double area = (a * a) * Math.Sin((RADIAN * theta));
return area;
}
public static void Main(String[] args)
{
int a = 4;
int theta = 60;
double ans = Area_of_Rhombus(a, theta);
Console.Write( "{0:F2}" , ans);
}
}
|
Javascript
<script>
function Area_of_Rhombus(a, theta){
var area = (a**2) * Math.sin(theta *Math.PI/180);
return area ;
}
a = 4
theta = 60
ans = Area_of_Rhombus(a, theta)
document.write(Math.round(ans * 100) / 100);
</script>
|
Time Complexity: O(1)
Auxiliary Space: O(1)
Last Updated :
07 Apr, 2021
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...