Area of a Regular Pentagram - GeeksforGeeks

04 Aug, 2021
Given a Pentagram and it’s inner side length(d). The task is find out area of Pentagram. The Pentagram is a five-pointed star that is formed by drawing a continuous line in five straight segments.
Examples: 
Input: d = 5 Output: Area = 139.187 Area of regular pentagram = 139.187 
Input: d = 7 Output: Area = 272.807  
Idea is to use Golden Ratio between a/b, b/c, and c/d which equals approximately 1.618 Inner side length d is given so c = 1.618 * d b = 1.618 * c a = 1.618 * bAB, BC and CD are equals(both side of regular pentagram) So AB = BC = CD = c and BD is given by d.
Area of pentagram = Area of Pentagon BDFHJ + 5 * (Area of triangle BCD) Area of Pentagon BDFHJ = (d^2 * 5)/ (4* tan 36) Area of triangle BCD = [s(s-d)(s-c)(s-c)]^(1/2) {Heron’s Formula} where s = (d + c + c)/2  
Below is the implementation of the above approach: 
C++
Java
Python3
C#
Javascript
// C++ implementation of the approach#include <bits/stdc++.h>#define PI 3.14159using namespace std; // Function to return the area of triangle BCDdouble areaOfTriangle(float d){    // Using Golden ratio    float c = 1.618 * d;    float s = (d + c + c) / 2;     // Calculate area of triangle BCD    double area = sqrt(s * (s - c) *                          (s - c) * (s - d));     // Return area of all 5 triangle are same    return 5 * area;} // Function to return the area of regular pentagondouble areaOfRegPentagon(float d){    // Calculate the area of regular    // pentagon using above formula    double cal = 4 * tan(PI / 5);    double area = (5 * d * d) / cal;     // Return area of regular pentagon    return area;} // Function to return the area of pentagramdouble areaOfPentagram(float d){    // Area of a pentagram is equal to the    // area of regular  pentagon and five times    // the area of Triangle    return areaOfRegPentagon(d) +                             areaOfTriangle(d);} // Driver codeint main(){    float d = 5;    cout << areaOfPentagram(d) << endl;     return 0;}
// Java implementation of above approachpublic class GFG{     static double PI = 3.14159;     // Function to return the area of triangle BCD    static double areaOfTriangle(float d)    {        // Using Golden ratio        float c = (float) (1.618 * d);        float s = (d + c + c) / 2;         // Calculate area of triangle BCD        double area = Math.sqrt(s * (s - c)                * (s - c) * (s - d));         // Return area of all 5 triangle are same        return 5 * area;    }     // Function to return the area of regular pentagon    static double areaOfRegPentagon(float d)    {        // Calculate the area of regular        // pentagon using above formula        double cal = 4 * Math.tan(PI / 5);        double area = (5 * d * d) / cal;         // Return area of regular pentagon        return area;    }     // Function to return the area of pentagram    static double areaOfPentagram(float d)    {        // Area of a pentagram is equal to the        // area of regular pentagon and five times        // the area of Triangle        return areaOfRegPentagon(d)                + areaOfTriangle(d);    }     // Driver code    public static void main(String[] args)    {        float d = 5;        System.out.println(areaOfPentagram(d));    }} // This code has been contributed by 29AjayKumar
# Python3 implementation of the approach import math PI = 3.14159 # Function to return the area of triangle BCDdef areaOfTriangle(d) :     # Using Golden ratio    c = 1.618 * d    s = (d + c + c) / 2     # Calculate area of triangle BCD    area = math.sqrt(s * (s - c) *                        (s - c) * (s - d))     # Return area of all 5 triangles are the same    return 5 * area  # Function to return the area of regular pentagondef areaOfRegPentagon(d) :         global PI    # Calculate the area of regular    # pentagon using above formula    cal = 4 * math.tan(PI / 5)    area = (5 * d * d) / cal         # Return area of regular pentagon    return area  # Function to return the area of pentagramdef areaOfPentagram(d) :     # Area of a pentagram is equal to the    # area of regular pentagon and five times    # the area of Triangle    return areaOfRegPentagon(d) + areaOfTriangle(d)  # Driver code d = 5print(areaOfPentagram(d))      # This code is contributed by ihritik
// C# implementation of the above approachusing System; class GFG{     static double PI = 3.14159;     // Function to return the area of triangle BCD    static double areaOfTriangle(float d)    {        // Using Golden ratio        float c = (float) (1.618 * d);        float s = (d + c + c) / 2;         // Calculate area of triangle BCD        double area = Math.Sqrt(s * (s - c)                * (s - c) * (s - d));         // Return area of all 5 triangle are same        return 5 * area;    }     // Function to return the area of regular pentagon    static double areaOfRegPentagon(float d)    {        // Calculate the area of regular        // pentagon using above formula        double cal = 4 * Math.Tan(PI / 5);        double area = (5 * d * d) / cal;         // Return area of regular pentagon        return area;    }     // Function to return the area of pentagram    static double areaOfPentagram(float d)    {        // Area of a pentagram is equal to the        // area of regular pentagon and five times        // the area of Triangle        return areaOfRegPentagon(d)                + areaOfTriangle(d);    }     // Driver code    public static void Main()    {        float d = 5;        Console.WriteLine(areaOfPentagram(d));    }} // This code has been contributed by ihritik
<script>// Javascript implementation of the approachvar PI = 3.14159 // Function to return the area of triangle BCDfunction areaOfTriangle(d){    // Using Golden ratio    var c = 1.618 * d;    var s = (d + c + c) / 2;     // Calculate area of triangle BCD    var area = Math.sqrt(s * (s - c) *                          (s - c) * (s - d));     // Return area of all 5 triangle are same    return 5 * area;} // Function to return the area of regular pentagonfunction areaOfRegPentagon( d){    // Calculate the area of regular    // pentagon using above formula    var cal = 4 * Math.tan(PI / 5);    var area = (5 * d * d) / cal;     // Return area of regular pentagon    return area;} // Function to return the area of pentagramfunction areaOfPentagram(d){    // Area of a pentagram is equal to the    // area of regular  pentagon and five times    // the area of Triangle    return areaOfRegPentagon(d) +                             areaOfTriangle(d);} // Driver codevar d = 5;document.write(areaOfPentagram(d).toFixed(3)); // This code is contributed by ShubhamSingh10</script>
139.187
 
Time Complexity : O(1) 
 
29AjayKumar
ihritik
ManasChhabra2
SHUBHAMSINGH10
sumitgumber28
anikakapoor
simmytarika5
area-volume-programs
C++ Programs
Geometric
Mathematical
Mathematical
Geometric
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
Passing a function as a parameter in C++
Program to implement Singly Linked List in C++ using class
cout in C++
Pi(π) in C++ with Examples
Const keyword in C++
Circle and Lattice Points
Closest Pair of Points using Divide and Conquer algorithm
How to check if two given line segments intersect?
Program for distance between two points on earth
How to check if a given point lies inside or outside a polygon?