#!/usr/bin/perl -w

# Calculate area, inner/outer radi, segment length and angle as seen from the center
# and area for the inner and outer circle
use strict;

my $pi = 2 * atan2(1,0);
my $s2 = sqrt(2);
my $s3 = sqrt(3);

sub area_dia($) {
    my $radi = shift;
    my $area = $pi * $radi * $radi;
}

sub n_eckeR($$) {
    my $n = shift;
    my $R = shift; # outer radius

    my $alfa = 360 / $n; # angle at center
    my $s = 0; # segment length
    my $r = 0; # inner radius
    my $A = 0; # area

    if ($n == 3) {
	$s = $R * $s3;
	$r = $R/2;
	$A = 0.75 * $R * $R * $s3;
    } elsif ($n == 4) {
	$s = $R * $s2;
	$r = $R/2 * $s2;
	$A = 2 * $R * $R;
    } elsif ($n == 5) {
	$s = $R / 2 * sqrt(10 - 2 * sqrt(5));
	$r = $R/4 * (sqrt(5) + 1);
	$A = 5 / 8 * $R * $R * sqrt(10 + 2 * sqrt(5));
    } elsif ($n == 6) {
	$s = $R;
	$r = $R/2 * $s3;
	$A = 1.5 * $R * $R * $s3;
    } elsif ($n == 8) {
	$s = $R * sqrt(2 - $s2);
	$r = $R/2 * sqrt(2 + $s2);
	$A = 2 * $R * $R * $s2;
    } elsif ($n == 10) {
	$s = $R / 2 * (sqrt(5) - 1);
	$r = $R/4 * sqrt(10 + 2 * sqrt(5));
	$A = 5 / 4 * $R * $R * sqrt(10 - 2 * sqrt(5));
    } else {
    }

    ( $n, $alfa, $s, $r, $R, $A );
}

sub n_eckeA($$) {
    my $n = shift;
    my $A = shift;

    my $alfa = 360 / $n; # angle at center
    my $s = 0; # segment length
    my $r = 0; # inner radius
    my $R = 0; # outer radius

    if ($n == 3) {
	$R = sqrt( 4*$A / ( 3*$s3 ) );
	$s = $R * $s3;
	$r = $R/2;
    } elsif ($n == 4) {
	$R = sqrt( $A/2 );
	$s = $R * $s2;
	$r = $R/2 * $s2;
    } elsif ($n == 5) {
	$R = sqrt( 8*$A / (5*sqrt(10 + 2 * sqrt(5))) );
	$s = $R / 2 * sqrt(10 - 2 * sqrt(5));
	$r = $R/4 * (sqrt(5) + 1);
    } elsif ($n == 6) {
	$R = sqrt( 2*$A / (3*$s3) );
	$s = $R;
	$r = $R/2 * $s3;
    } elsif ($n == 8) {
	$R = sqrt( $A / (2*$s2) );
	$s = $R * sqrt(2 - $s2);
	$r = $R/2 * sqrt(2 + $s2);
    } elsif ($n == 10) {
	$R = sqrt( 4*$A / (5*sqrt(10 - 2 * sqrt(5))) );
	$s = $R / 2 * (sqrt(5) - 1);
	$r = $R/4 * sqrt(10 + 2 * sqrt(5));
    } else {
    }

    ( $n, $alfa, $s, $r, $R, $A );
}

sub main() {
    my ( $n, $alfa, $s, $r, $R, $A );
    if (@ARGV != 2) { return; }
    $n = shift @ARGV;
    $A = shift @ARGV;

    ( $n, $alfa, $s, $r, $R, $A ) = n_eckeA($n, $A);
#    ( $n, $alfa, $s, $r, $R, $A ) = n_eckeR($n, $R);
    print "$n, $alfa, $s, $r, $R, $A\n";

    print area_dia($r), " ", area_dia($R), "\n";
}

main();
