find the surface area of a regular polygon circumscribed around a cylinder in go

To find the surface area of a regular polygon circumscribed around a cylinder, we need to calculate the area of the top and bottom faces of the cylinder, as well as the area of the lateral surface that makes up the sides of the cylinder.

To begin, let's define some important terms:

  • radius (r) of the cylinder
  • height (h) of the cylinder
  • number of sides (n) of the regular polygon

We can use the math package in Go to perform some of these calculations. Here is an example code snippet:

main.go
package main

import (
	"fmt"
	"math"
)

func main() {

	r := 5.0 // radius of cylinder
	h := 10.0 // height of cylinder
	n := 6.0 // number of sides of regular polygon

	// area of each triangular face
	polygonSide := 2 * r * math.Sin(math.Pi/n)
	areaTriangle := 0.5 * polygonSide * r

	// area of lateral surface
	areaLateral := n * areaTriangle

	// area of top and bottom faces
	areaTopBottom := 2 * math.Pi * r * h

	// total surface area
	totalArea := areaLateral + areaTopBottom

	fmt.Println("Surface area of regular polygon circumscribed around cylinder:", totalArea)
}
579 chars
29 lines

In this example, we have defined the radius (r) and height (h) of the cylinder, as well as the number of sides (n) of the regular polygon. Using these variables, we calculate the area of each triangular face (areaTriangle) and the area of the lateral surface (areaLateral). We also calculate the area of the top and bottom faces (areaTopBottom) and then add all of these areas together to get the total surface area of the cylinder.

This code outputs the surface area of a cylinder with radius of 5, height of 10 and circumscribing a regular hexagon to be approximately 417.832...

gistlibby LogSnag