find the surface area of a regular polygon circumscribed around a cone in php

To find the surface area of a regular polygon circumscribed around a cone, we need to calculate the area of the base and the lateral area.

To calculate the area of the base, we need to find the side length of the regular polygon, which can be calculated as follows:

main.php
function calcPolygonSideLength($numSides, $radius) {
  $angle = 2 * pi() / $numSides;
  $sideLength = 2 * $radius * sin($angle / 2);
  return $sideLength;
}
157 chars
6 lines

where $numSides is the number of sides of the polygon and $radius is the radius of the circle that circumscribes the polygon.

Once we have the side length of the polygon, we can calculate the area of the base as follows:

main.php
function calcPolygonArea($numSides, $radius) {
  $sideLength = calcPolygonSideLength($numSides, $radius);
  $apothem = $radius * cos(pi() / $numSides);
  $area = 0.5 * $numSides * $sideLength * $apothem;
  return $area;
}
222 chars
7 lines

where $apothem is the distance between the center of the circumscribing circle and the midpoint of a side of the polygon.

To calculate the lateral area, we need to find the slant height of the cone and the perimeter of the regular polygon, which can be calculated as follows:

main.php
function calcSlantHeight($radius, $height) {
  $slantHeight = sqrt(pow($radius, 2) + pow($height, 2));
  return $slantHeight;
}

function calcPolygonPerimeter($numSides, $sideLength) {
  $perimeter = $numSides * $sideLength;
  return $perimeter;
}
248 chars
10 lines

Once we have the slant height and the perimeter of the polygon, we can calculate the lateral area as follows:

main.php
function calcLateralArea($numSides, $radius, $height) {
  $slantHeight = calcSlantHeight($radius, $height);
  $sideLength = calcPolygonSideLength($numSides, $radius);
  $perimeter = calcPolygonPerimeter($numSides, $sideLength);
  $area = 0.5 * $perimeter * $slantHeight;
  return $area;
}
289 chars
8 lines

Finally, we can calculate the surface area of the regular polygon circumscribed around the cone by adding the area of the base and the lateral area:

main.php
function calcSurfaceArea($numSides, $radius, $height) {
  $baseArea = calcPolygonArea($numSides, $radius);
  $lateralArea = calcLateralArea($numSides, $radius, $height);
  $area = $baseArea + $lateralArea;
  return $area;
}
224 chars
7 lines

We can call the calcSurfaceArea function with the appropriate arguments to get the surface area of the regular polygon circumscribed around the cone.

gistlibby LogSnag