Monday, November 18, 2024
Google search engine
HomeData Modelling & AIPython Program for Program to calculate area of a Tetrahedron

Python Program for Program to calculate area of a Tetrahedron

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 or the base and four vertices or corners. If the faces are all congruent equilateral triangles, then the tetrahedron is called regular. 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

Python3




# Python code to find the volume of a tetrahedron
 
import math
 
 
def vol_tetra(side):
    volume = (side ** 3 / (6 * math.sqrt(2)))
    return round(volume, 2)
 
 
# Driver Code
side = 3
vol = vol_tetra(side)
print(vol)


Output

3.18

Time complexity: O(1) since no loop is used the algorithm takes up constant time to perform the operations
Auxiliary Space: O(1)  since no extra array is used so the space taken by the algorithm is constant

Approach: In order to calculate the area of a tetrahedron, we need to know the length of one of its sides. Once we have the length of the side, we can use the following formula to calculate the area:
area = sqrt(3) * s^2

where s is the length of the side of the tetrahedron.

Steps:

  1. Take the input of the length of the side of the tetrahedron.
  2. Calculate the area using the formula.
  3. Print the calculated area.

Python3




import math
 
 
def calculate_tetrahedron_area(side):
    area = math.sqrt(3) * side ** 2 / 4
    return round(area, 2)
 
 
# Example usage:
side = 3
area = calculate_tetrahedron_area(side)
print("The area of a tetrahedron with side", side, "is", area)


Output

The area of a tetrahedron with side 3 is 3.9

Time Complexity: O(1) 
Auxiliary Space: O(1)

Please refer complete article on Program to calculate area of a Tetrahedron for more details!

Feeling lost in the world of random DSA topics, wasting time without progress? It’s time for a change! Join our DSA course, where we’ll guide you on an exciting journey to master DSA efficiently and on schedule.
Ready to dive in? Explore our Free Demo Content and join our DSA course, trusted by over 100,000 neveropen!

RELATED ARTICLES

Most Popular

Recent Comments