#include <math.h>
#include <stdio.h>

#define PI	3.1415927
#define unchar	unsigned char

FILE *fpw0;

main()
{
	/****** ram set ******/
	float s,ss;
	long i,psum,n,angle,x,y,radius,vwide,hwide;

	/***** init. set *****/
	printf("How many points ( corner ) ?\t");
	scanf("%x", &psum);
	printf("How long a radius ?\t");
	scanf("%x", &radius);
	printf("How long V line wide ( corner )?\t");
	scanf("%x", &vwide);
	printf("How long H line wide ( corner )?\t");
	scanf("%x", &hwide);
	n=psum-1;
	angle=90/n;
	n=psum*2;

	/****** write file open ******/
	if((fpw0=fopen("bg3pol2.dat","w")) == 0){
		printf("can't open !!\n");
		exit(1);
	}

	/****** BG3 POLYGON data make ******/
	for(i=0;i<n;i++){
		ss=s=180.0-i*angle;
		if(s>90){
			ss=180.0-s;
		}

		ss=ss*PI/180;
		x=cos(ss)*radius;
		y=sin(ss)*radius+vwide;

		if(s>90){
			x=-x-hwide;
		}
		else	x+=hwide;

		fprintf(fpw0,"\n\t\tHEX\t%03X,%03X",(unchar)x,(unchar)y);
	}
	for(i=n-1;i>=0;i--){
		ss=s=i*angle;
		if(s>90){
			ss=180.0-s;
		}

		ss=ss*PI/180;
		x=cos(ss)*radius;
		y=-(sin(ss)*radius+vwide);

		if(s<90){
			x=-x-hwide;
		}
		else	x+=hwide;

		fprintf(fpw0,"\n\t\tHEX\t%03X,%03X",(unchar)x,(unchar)y);
	}

	fprintf(fpw0,"\n");

        /****** write file close ******/
	fclose(fpw0);
}
