import java.applet.*;
import java.awt.*;
public class Exercise7_1_2 extends Applet {
public final double R=150.0f;
int x[]=new int [10],y[]=new int[10],i;
double dx[]=new double[10],dy[]=new double[10];//先计算出浮点坐标,是考虑到后续计算的精度
public void init(){
setSize(400,400);
//计算五个外角顶点坐标
int j,angle;
for(i=0;i<5;i++){
j=2*i;
angle=-i*72-18;
dx[j]=R*Math.cos(3.1415926/180.0*angle);
dy[j]=R*Math.sin(3.1415926/180.0*angle);
}
//计算五个内角顶点坐标
int p1,p2,p3,p4,p5;
double t1,t2;
for(i=0;i<10;i=i+2){
p1=i;
p2=(i+4)%10;
p3=(i+8)%10;
p4=(i+2)%10;
p5=i+1;
t1=(dy[p2]-dy[p1])/(dx[p2]-dx[p1]);
t2=(dy[p4]-dy[p3])/(dx[p4]-dx[p3]);
dx[p5]=(t1*dx[p1]-t2*dx[p3]+dy[p3]-dy[p1])/(t1-t2);
dy[p5]=t1*(dx[p5]-dx[p1])+dy[p1];
}
//计算十个点的整数坐标
for(i=0;i<10;i++){
x[i]=((int)dx[i])+200;
y[i]=((int)dy[i])+200;
}
}
public void paint(Graphics g){
/*g.setColor(Color.blue);
g.drawOval(50,50,300,300);//画出外接圆*/
Polygon ryesky=new Polygon(x,y,10);
g.setColor(Color.red);
g.fillPolygon(ryesky);
}
}
转载于:https://blog.51cto.com/4951451/957747