How to Calculate the Area of a Tetrahedron in Swift?


Tetrahedron is a 3−D triangular pyramid shape whose base is also a triangle. Generally, a tetrahedron contains four equilateral triangles, hence it has interior angles of 60 degrees.

In Swift, we can calculate the area of a tetrahedron using the following formula:

Formula

$$\mathrm{Area=\sqrt{3}*X*X}$$

Here, x represents the side of the tetrahedron.

If you wish to find the area of one side of a tetrahedron then you can use the following formula:

Formula

$$\mathrm{Area\:of\:one\:side\:of\:tetrahedron =(\sqrt{3}*y*y)/4}$$

Here, y represents the side of the tetrahedron.

Algorithm

Step 1 − Create a function which takes the side of the tetrahedron as a parameter and returns the area.

Step 2 − Inside the function, we will use the mathematical formula to find the area of a tetrahedron and store the result in a variable.

Step 3 − Return the area of a tetrahedron.

Step 4 − Define the side of the tetrahedron, or can take from the user.

Step 5 − Call the above create function and pass the side into it.

Step 6 − Display the result.

Example 1: Area of Tetrahedron

In the following Swift program, we will calculate the area of a tetrahedron. So for that, we create a function named areaOfTetrahedron(). This function takes the side as a parameter and finds the area using the formula, where we will use sqrt() function to find the square root of the 3 and return the final area of a tetrahedron.

import Foundation
import Glibc

// Function to find the area of Tetrahedron
func areaOfTetrahedron(inputSide: Double)-> Double{
    let resultantArea = sqrt(3) * inputSide * inputSide
    return resultantArea
}

// Test case
let side = 4.0

// Calling the function
let resultant = areaOfTetrahedron(inputSide:side)

// Displaying the result
print("Sides:", side)
print("Area of Tetrahedron:", resultant)

Output

Sides: 4.0
Area of Tetrahedron: 27.712812921102035

Example 2: Area of One Face of Tetrahedron

In the following Swift program, we will calculate the area of one face of a tetrahedron. So for that, we create a function named areaOfOneFace(). This function takes the side as a parameter and finds the area of one face of a tetrahedron using the given formula. Return the final area of one face of a tetrahedron.

import Foundation
import Glibc

// Function to find the area of one face of the Tetrahedron
func areaOfOneFace(inputSide: Double)-> Double{
    let resultantArea = (sqrt(3) * inputSide * inputSide) / 4
    return resultantArea
}

// Test case
let side = 2.0

// Calling the function
let resultant = areaOfOneFace(inputSide:side)

// Displaying the result
print("Sides:", side)
print("Area of one side of Tetrahedron:", resultant)

Output

Sides: 2.0
Area of one side of Tetrahedron: 1.7320508075688772

Real−Life Usage

The real−life usage of the area of a tetrahedron:

  • It is used to maintain the mesh quality of tetrahedral meshing in computer geometry and computer graphics.

  • It is sometimes used in crystalline structures.

  • It is commonly used in educational departments to illustrate geometric concepts.

Conclusion

So this is how we can calculate the area of a tetrahedron. A tetrahedron has four faces so it is generally used in arts, architecture, etc. Pyramids of Gaza, salt crystals, tents, and molecules are real−life examples of tetrahedrons.

Updated on: 08-Sep-2023

37 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements