#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;

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

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

	/****** BG3 POLYGON data make ******/
	fprintf(fpw0,"\n\t\tHEX\t%03X",psum*2);

	for(i=0;i<psum;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;

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

	for(i=psum-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;

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

	fprintf(fpw0,"\n");

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