A tetrahedron is simply a pyramid with a triangular base. It is a solid object with four triangular faces, three on the sides or lateral faces, one on the bottom of the base, and four vertices or corners. If the faces are all congruent equilateral triangles, then the tetrahedron is called regular.
The area of the Tetrahedron can be found by using the formula:
Area = sqrt(3)*(side*side)
Illustration:
Input: side = 3
Output: 15.5885
Input: side = 20
Output: 692.82
Example
C++
#include <iostream>
#include <math.h>
using namespace std;
double area_of_tetrahedron( int side)
{
return ( sqrt (3) * (side * side));
}
int main()
{
int side = 3;
cout << "Area of Tetrahedron ="
<< area_of_tetrahedron(side);
}
|
Java
import java.io.*;
import java.text.DecimalFormat;
class GFG
{
static double area_of_tetrahedron( int side)
{
return ( double )Math.round((Math.sqrt( 3 ) *
(side * side)) * 10000d) / 10000d;
}
public static void main(String args[])
{
int side = 3 ;
System.out.print( "Area of Tetrahedron = " +
area_of_tetrahedron(side));
}
}
|
Python 3
import math
def area_of_tetrahedron(side):
return (math.sqrt( 3 ) * (side * side))
side = 3 ;
print ( "Area of Tetrahedron =" ,
area_of_tetrahedron(side));
|
C#
using System;
class GFG
{
static double area_of_tetrahedron( int side)
{
return (Math.Sqrt(3) *
(side * side));
}
static void Main()
{
int side = 3;
Console.Write( "Area of Tetrahedron = " +
area_of_tetrahedron(side));
}
}
|
PHP
<?php
function area_of_tetrahedron( $side )
{
return (sqrt(3) *
( $side * $side ));
}
$side =3;
echo "Area of Tetrahedron =" ,
area_of_tetrahedron( $side );
?>
|
Javascript
<script>
function area_of_tetrahedron(side)
{
return (Math.sqrt(3) * (side * side));
}
var side = 3;
document.write( "Area of Tetrahedron =" + area_of_tetrahedron(side));
</script>
|
OutputArea of Tetrahedron =15.5885
Time Complexity: O(1)
because it is doing constant operations
Auxiliary Space: O(1)
Another approach:
The volume of the tetrahedron can be found by using the following formula:
Volume = a3/(6√2)
Examples:
Input: side = 3
Output: 3.18
Input: side = 20
Output: 942.81
C++
#include <bits/stdc++.h>
using namespace std;
static double vol_tetra( int side)
{
double volume
= ( pow (side, 3) / (6 * sqrt (2)));
return volume;
}
int main()
{
int side = 3;
double vol = vol_tetra(side);
cout << vol << "\n" ;
return 0;
}
|
Java
import java.io.*;
class GFG {
static double vol_tetra( int side)
{
double volume
= (Math.pow(side, 3 ) / ( 6 * Math.sqrt( 2 )));
return volume;
}
public static void main(String[] args)
{
int side = 3 ;
double vol = vol_tetra(side);
System.out.println(vol);
}
}
|
Python 3
import math
def vol_tetra(side):
volume = ( pow (side, 3 ) / ( 6 * math.sqrt( 2 )))
return volume;
if __name__ = = "__main__" :
side = 3
vol = vol_tetra(side)
print ( round (vol, 2 ))
|
C#
using System;
class GFG
{
static double vol_tetra( int side)
{
double volume = (Math.Pow(side, 3 ) /
( 6 * Math.Sqrt( 2 )));
return volume;
}
public static void Main ()
{
int side = 3 ;
double vol = vol_tetra(side);
Console.WriteLine( vol);
}
}
|
PHP
<?php
function vol_tetra( $side )
{
$volume = (pow( $side , 3) /
(6 * sqrt(2)));
return $volume ;
}
$side = 3;
$vol = vol_tetra( $side );
echo $vol ;
?>
|
Javascript
<script>
function vol_tetra(side) {
var volume = parseInt((Math.pow(side, 3) /
(6 * Math.sqrt(2))));
return volume;
}
var side = 3;
var vol = vol_tetra(side);
document.write(vol);
</script>
|
Time Complexity: O(1), As we are not using any looping statements.
Auxiliary Space: O(1)
Please refer complete article on Program to calculate area and volume of a Tetrahedron for more details!