Area of a Regular Pentagram | Javascript implementation of the approach ; Function to return the area of triangle BCD ; Using Golden ratio ; Calculate area of triangle BCD ; Return area of all 5 triangle are same ; Function to return the area of regular pentagon ; Calculate the area of regular pentagon using above formula ; Return area of regular pentagon ; Function to return the area of pentagram ; Area of a pentagram is equal to the area of regular pentagon and five times the area of Triangle ; Driver code
var PI = 3.14159 function areaOfTriangle ( d ) { var c = 1.618 * d ; var s = ( d + c + c ) / 2 ; var area = Math . sqrt ( s * ( s - c ) * ( s - c ) * ( s - d ) ) ; return 5 * area ; } function areaOfRegPentagon ( d ) { var cal = 4 * Math . tan ( PI / 5 ) ; var area = ( 5 * d * d ) / cal ; return area ; } function areaOfPentagram ( d ) { return areaOfRegPentagon ( d ) + areaOfTriangle ( d ) ; } var d = 5 ; document . write ( areaOfPentagram ( d ) . toFixed ( 3 ) ) ;