Area of the circumcircle of any triangles with sides given
Given a triangle with known sides a, b and c; the task is to find the area of its circumcircle.
Examples:
Input: a = 2, b = 2, c = 3
Output: 7.17714
Input: a = 4, b = 5, c = 3
Output: 19.625
Approach:
For a triangle with side lengths a, b, and c,
Radius of the circumcircle:
[Tex]= \frac{abc}{4\sqrt{\left ( s\left ( a+b-s \right )\left ( a+c-s \right )\left ( b+c-s \right ) \right )}}[/Tex]where A = √(s*(s-a)*(s-b)*(s-c))and s = (a+b+c)/2 is the semiperimeter.Therefore, Area of the circumcircle:
Below is the implementation of the above approach:
C++
#include <bits/stdc++.h>
using namespace std;
float circlearea( float a, float b, float c)
{
if (a < 0 || b < 0 || c < 0)
return -1;
float p = (a + b + c) / 2;
float At = sqrt (p * (p - a) * (p - b) * (p - c));
float A = 3.14 * pow (((a * b * c) / (4 * At)), 2);
return A;
}
int main()
{
float a = 4, b = 5, c = 3;
cout << circlearea(a, b, c) << endl;
return 0;
}
|
Java
import java.*;
class gfg
{
public double circlearea( double a, double b, double c)
{
if (a < 0 || b < 0 || c < 0 )
return - 1 ;
double p = (a + b + c) / 2 ;
double At = Math.sqrt(p * (p - a) * (p - b) * (p - c));
double A = 3.14 * Math.pow(((a * b * c) / ( 4 * At)), 2 );
return A;
}
}
class geek
{
public static void main(String[] args)
{
gfg g = new gfg();
double a = 4 , b = 5 , c = 3 ;
System.out.println(g.circlearea(a, b, c));
}
}
|
Python3
import math
def circlearea(a, b, c):
if (a < 0 or b < 0 or c < 0 ):
return - 1 ;
p = (a + b + c) / 2 ;
At = math.sqrt(p * (p - a) *
(p - b) * (p - c));
A = 3.14 * pow (((a * b * c) / ( 4 * At)), 2 );
return A;
a = 4 ;
b = 5 ;
c = 3 ;
print ( float (circlearea(a, b, c)));
|
C#
using System;
class gfg
{
public double circlearea( double a, double b, double c)
{
if (a < 0 || b < 0 || c < 0)
return -1;
double p = (a + b + c) / 2;
double At = Math.Sqrt(p * (p - a) * (p - b) * (p - c));
double A = 3.14 * Math.Pow(((a * b * c) / (4 * At)), 2);
return A;
}
}
class geek
{
public static int Main()
{
gfg g = new gfg();
double a = 4, b = 5, c = 3;
Console.WriteLine(g.circlearea(a, b, c));
return 0;
}
}
|
PHP
<?php
function circlearea( $a , $b , $c )
{
if ( $a < 0 || $b < 0 || $c < 0)
return -1;
$p = ( $a + $b + $c ) / 2;
$At = sqrt( $p * ( $p - $a ) *
( $p - $b ) * ( $p - $c ));
$A = 3.14 * pow((( $a * $b *
$c ) / (4 * $At )), 2);
return $A ;
}
$a = 4; $b = 5; $c = 3;
echo circlearea( $a , $b , $c );
?>
|
Javascript
<script>
function circlearea(a , b , c)
{
if (a < 0 || b < 0 || c < 0)
return -1;
var p = (a + b + c) / 2;
var At = Math.sqrt(p * (p - a) * (p - b) * (p - c));
var A = 3.14 * Math.pow(((a * b * c) / (4 * At)), 2);
return A;
}
var a = 4, b = 5, c = 3;
document.write(circlearea(a, b, c));
</script>
|
Time Complexity: O(log(n)) as it is using inbuilt sqrt function
Auxiliary Space: O(1)
Last Updated :
27 Aug, 2022
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...