Posted on by Kalkicode
Code Geometric

Find volume of Icosahedron

An icosahedron is a three-dimensional geometric solid with 20 equilateral triangle faces. Finding the volume of an icosahedron involves calculating the amount of space enclosed within its boundaries. This calculation is important in geometry and architecture, where icosahedrons are used to model certain structures and crystals.

Problem Statement

Given the length of the side of the icosahedron, the task is to calculate its volume. The formula for finding the volume of an icosahedron in terms of its side length 's' is:

Volume = (5/12) * (3 + √5) * s³

Example Scenario

Imagine you are a crystallographer studying the molecular arrangement of certain compounds. To understand the internal space occupied by the molecule, you need to calculate the volume of the icosahedral crystal structure. This calculation helps you analyze the molecule's characteristics and interactions.

Idea to Solve the Problem

To solve this problem, we can follow these steps:

  1. Accept the side length of the icosahedron as input.
  2. Use the formula to calculate the volume of the icosahedron.
  3. Display the calculated volume.

Pseudocode

function icosahedron_volume(side):
    volume = (5/12) * (3 + √5) * (side * side * side)
    return volume

main:
    side1 = 4
    side2 = 8
    side3 = 13.6
    
    volume1 = icosahedron_volume(side1)
    volume2 = icosahedron_volume(side2)
    volume3 = icosahedron_volume(side3)
    
    print("Icosahedron [ Side :", side1, "]")
    print("Volume :", volume1)
    
    print("Icosahedron [ Side :", side2, "]")
    print("Volume :", volume2)
    
    print("Icosahedron [ Side :", side3, "]")
    print("Volume :", volume3)

Algorithm Explanation

  1. Define a function icosahedron_volume that takes the side length as input.
  2. Inside the function, use the provided formula to calculate the volume of the icosahedron.
  3. In the main function, set three test cases with different values for the side length.
  4. Calculate the volumes for each test case by calling the icosahedron_volume function.
  5. Display the calculated volumes along with their respective side length values.

Code Solution

//C Program
//Find volume of Icosahedron
#include <stdio.h>

#include <math.h>
 //Calculate volume of Icosahedron by given side
void icosahedron_volume(double side)
{
  //Calculate Formula
  //5/12 (3 + √5)(side³)
  double volume = ((double) 5 / 12) * (3 + sqrt(5)) * (side * side * side);
  //Display the result of icosahedron volume
  printf(" Icosahedron  [ Side : %lf ] ", side);
  printf("\n Volume : %lf\n\n", volume);
}
int main()
{
  //Test Cases  
  icosahedron_volume(4);
  icosahedron_volume(8);
  icosahedron_volume(13.6);
  return 0;
}

Output

 Icosahedron  [ Side : 4.000000 ]
 Volume : 139.628479

 Icosahedron  [ Side : 8.000000 ]
 Volume : 1117.027835

 Icosahedron  [ Side : 13.600000 ]
 Volume : 5487.957754
// Java Program
// Find volume of Icosahedron
class IcosahedronVolume
{
  //Calculate volume of Icosahedron by given side
  public void icosahedron_volume(double side)
  {
    //Calculate Formula
    //5/12 (3 + √5)(side³)
    double volume = ((double) 5 / 12) * (3 + Math.sqrt(5)) * (side * side * side);
    //Display the result of icosahedron volume
    System.out.print(" Icosahedron [ Side : " + side + " ] ");
    System.out.print("\n Volume : " + volume + "\n\n");
  }
  public static void main(String[] args)
  {
    IcosahedronVolume obj = new IcosahedronVolume();
    //Test Cases  
    obj.icosahedron_volume(4);
    obj.icosahedron_volume(8);
    obj.icosahedron_volume(13.6);
  }
}

Output

 Icosahedron [ Side : 4.0 ]
 Volume : 139.6284793999944

 Icosahedron [ Side : 8.0 ]
 Volume : 1117.0278351999552

 Icosahedron [ Side : 13.6 ]
 Volume : 5487.95775433738
// C++ Program
// Find volume of Icosahedron
#include<iostream>
#include <math.h>
using namespace std;
class IcosahedronVolume
{
  public:
    //Calculate volume of Icosahedron by given side
    void icosahedron_volume(double side)
    {
      //Calculate Formula
      //5/12 (3 + √5)(side³)
      double volume = ((double) 5 / 12) *(3 + sqrt(5)) *(side *side *side);
      cout << " Icosahedron [ Side : " << side << " ] ";
      cout << "\n Volume : " << volume << "\n\n";
    }
};
int main()
{
  IcosahedronVolume obj =  IcosahedronVolume();
  //Test Cases  
  obj.icosahedron_volume(4);
  obj.icosahedron_volume(8);
  obj.icosahedron_volume(13.6);
  return 0;
}

Output

 Icosahedron [ Side : 4 ]
 Volume : 139.628

 Icosahedron [ Side : 8 ]
 Volume : 1117.03

 Icosahedron [ Side : 13.6 ]
 Volume : 5487.96
// C# Program
// Find volume of Icosahedron
using System;
class IcosahedronVolume
{
  //Calculate volume of Icosahedron by given side
  public void icosahedron_volume(double side)
  {
    //Calculate Formula
    //5/12 (3 + √5)(side³)
    double volume = ((double) 5 / 12) * (3 + Math.Sqrt(5)) * (side * side * side);
    Console.Write(" Icosahedron [ Side : " + side + " ] ");
    Console.Write("\n Volume : " + volume + "\n\n");
  }
  public static void Main(String[] args)
  {
    IcosahedronVolume obj = new IcosahedronVolume();
    //Test Cases  
    obj.icosahedron_volume(4);
    obj.icosahedron_volume(8);
    obj.icosahedron_volume(13.6);
  }
}

Output

 Icosahedron [ Side : 4 ]
 Volume : 139.628479399994

 Icosahedron [ Side : 8 ]
 Volume : 1117.02783519996

 Icosahedron [ Side : 13.6 ]
 Volume : 5487.95775433738
<?php
// Php Program
// Find volume of Icosahedron
class IcosahedronVolume
{
  //Calculate volume of Icosahedron by given side
  public  function icosahedron_volume($side)
  {
    //Calculate Formula
    //5/12 (3 + √5)(side³)
    $volume = (5 / 12) *(3 + sqrt(5)) *($side *$side *$side);
    //Display the result of icosahedron volume
    echo(" Icosahedron [ Side : ". $side ." ] ");
    echo("\n Volume : ". $volume ."\n\n");
  }
}

function main()
{
  $obj = new IcosahedronVolume();
  //Test Cases  
  $obj->icosahedron_volume(4);
  $obj->icosahedron_volume(8);
  $obj->icosahedron_volume(13.6);
}
main();

Output

 Icosahedron [ Side : 4 ]
 Volume : 139.62847939999

 Icosahedron [ Side : 8 ]
 Volume : 1117.0278352

 Icosahedron [ Side : 13.6 ]
 Volume : 5487.9577543374
// Node Js Program
// Find volume of Icosahedron
class IcosahedronVolume
{
  //Calculate volume of Icosahedron by given side
  icosahedron_volume(side)
  {
    //Calculate Formula
    //5/12 (3 + √5)(side³)
    var volume = (5 / 12) *(3 + Math.sqrt(5)) *(side *side *side);
    //Display the result of icosahedron volume
    process.stdout.write(" Icosahedron [ Side : " + side + " ] ");
    process.stdout.write("\n Volume : " + volume + "\n\n");
  }
}

function main(args)
{
  var obj = new IcosahedronVolume();
  //Test Cases  
  obj.icosahedron_volume(4);
  obj.icosahedron_volume(8);
  obj.icosahedron_volume(13.6);
}
main();

Output

 Icosahedron [ Side : 4 ]
 Volume : 139.6284793999944

 Icosahedron [ Side : 8 ]
 Volume : 1117.0278351999552

 Icosahedron [ Side : 13.6 ]
 Volume : 5487.95775433738
#  Python 3 Program
#  Find volume of Icosahedron
import math
class IcosahedronVolume :
  # Calculate volume of Icosahedron by given side
  def icosahedron_volume(self, side) :
    # Calculate Formula
    # 5/12 (3 + √5)(side³)
    volume = (5 / 12) * (3 + math.sqrt(5)) * (side * side * side)
    # Display the result of icosahedron volume
    print(" Icosahedron [ Side : ", side , end = " ]")
    print("\n Volume : ", volume ,"\n")
  

def main() :
  obj = IcosahedronVolume()
  # Test Cases  
  obj.icosahedron_volume(4)
  obj.icosahedron_volume(8)
  obj.icosahedron_volume(13.6)


if __name__ == "__main__": main()

Output

 Icosahedron [ Side :  4 ]
 Volume :  139.6284793999944

 Icosahedron [ Side :  8 ]
 Volume :  1117.0278351999552

 Icosahedron [ Side :  13.6 ]
 Volume :  5487.95775433738
#  Ruby Program
#  Find volume of Icosahedron
class IcosahedronVolume

  # Calculate volume of Icosahedron by given side
  def icosahedron_volume(side)
  
    # Calculate Formula
    # 5/12 (3 + √5)(side³)
    volume = (5.0 / 12) * (3 + Math.sqrt(5)) * (side * side * side)
    # Display the result of icosahedron volume
    print(" Icosahedron [ Side  : ", side ," ] ")
    print("\n Volume  : ", volume ,"\n\n")
  end
end
def main()

  obj = IcosahedronVolume.new()
  # Test Cases  
  obj.icosahedron_volume(4)
  obj.icosahedron_volume(8)
  obj.icosahedron_volume(13.6)
end
main()

Output

 Icosahedron [ Side  : 4 ] 
 Volume  : 139.6284793999944

 Icosahedron [ Side  : 8 ] 
 Volume  : 1117.0278351999552

 Icosahedron [ Side  : 13.6 ] 
 Volume  : 5487.95775433738

// Scala Program
// Find volume of Icosahedron
class IcosahedronVolume
{
  //Calculate volume of Icosahedron by given side
  def icosahedron_volume(side: Double): Unit = {
    //Calculate Formula
    //5/12 (3 + √5)(side³)
    var volume: Double = (5.0 / 12) * (3 + Math.sqrt(5)) * (side * side * side);
    //Display the result of icosahedron volume
    print(" Icosahedron [ Side : " + side + " ] ");
    print("\n Volume : " + volume + "\n\n");
  }
}
object Main
{
  def main(args: Array[String]): Unit = {
    var obj: IcosahedronVolume = new IcosahedronVolume();
    //Test Cases  
    obj.icosahedron_volume(4);
    obj.icosahedron_volume(8);
    obj.icosahedron_volume(13.6);
  }
}

Output

 Icosahedron [ Side : 4.0 ]
 Volume : 139.6284793999944

 Icosahedron [ Side : 8.0 ]
 Volume : 1117.0278351999552

 Icosahedron [ Side : 13.6 ]
 Volume : 5487.95775433738
// Swift Program
// Find volume of Icosahedron
import Foundation
class IcosahedronVolume
{
  //Calculate volume of Icosahedron by given side
  func icosahedron_volume(_ side: Double)
  {
    //Calculate Formula
    //5/12 (3 + √5)(side³)
    let volume: Double = (5 / 12) * (3 + sqrt(5)) * (side * side * side);
    //Display the result of icosahedron volume
    print(" Icosahedron [ Side : ", side , terminator: " ]");
    print("\n Volume : ", volume ,"\n");
  }
}
func main()
{
  let obj: IcosahedronVolume = IcosahedronVolume();
  //Test Cases  
  obj.icosahedron_volume(4);
  obj.icosahedron_volume(8);
  obj.icosahedron_volume(13.6);
}
main();

Output

 Icosahedron [ Side :  4.0 ]
 Volume :  139.628479399994

 Icosahedron [ Side :  8.0 ]
 Volume :  1117.02783519996

 Icosahedron [ Side :  13.6 ]
 Volume :  5487.95775433738

Output Explanation

The code calculates the volume for each test case and displays the results. For an icosahedron with a side length of 4, the volume is approximately 139.628479. Similarly, for a side length of 8, the volume is approximately 1117.027835. The third test case follows the same pattern with a different set of values.

Time Complexity

The time complexity of this code is constant O(1) because the calculations involve basic arithmetic operations and the value of the square root of 5, which are calculated in constant time regardless of the input size. The program performs a fixed number of operations for each test case, making it efficient.

Comment

Please share your knowledge to improve code and content standard. Also submit your doubts, and test case. We improve by your feedback. We will try to resolve your query as soon as possible.

New Comment