Find the length of Kth N | Javascript program for the above approach ; Function to calculate the interior angle of a N - sided regular polygon ; Function to find the K - th polygon formed inside the ( K - 1 ) th polygon ; Stores the interior angle ; Stores the side length of K - th regular polygon ; Return the length ; Driver Code
const PI = 3.14159265 function findInteriorAngle ( n ) { return ( n - 2 ) * PI / n ; } function calculateSideLength ( L , N , K ) { let angle = findInteriorAngle ( N ) ; let length = L * Math . pow ( Math . sin ( angle / 2 ) , ( K - 1 ) ) ; return length ; } let N = 5 let L = 21 let K = 7 ; document . write ( calculateSideLength ( L , N , K ) )