用角来算不可以吗?转贴
import java.lang.Math;int PosX[], PosY[];
PosX[] = new int[5];
PosY[] = new int[5];int i;
double angle;
angle = 2 * Math.PI / 5;
// 假设这正五角星形五个顶点的中心点在(200,300)圆周半径为150
for(i = 0; i <= 4; i++)
{
PosX[i] = 200 + 150 * cos(angle * i);
PosY[i] = 300 + 150 * sin(angle * i);
}//接下来假设这五点为
// d
// c e
// b a 其中假设a坐标为(PosX[0], PosY[0])
// b坐标为(PosX[1], PosY[1])~~如此类推
import java.lang.Math;int PosX[], PosY[];
PosX[] = new int[5];
PosY[] = new int[5];int i;
double angle;
angle = 2 * Math.PI / 5;
// 假设这正五角星形五个顶点的中心点在(200,300)圆周半径为150
for(i = 0; i <= 4; i++)
{
PosX[i] = 200 + 150 * cos(angle * i);
PosY[i] = 300 + 150 * sin(angle * i);
}//接下来假设这五点为
// d
// c e
// b a 其中假设a坐标为(PosX[0], PosY[0])
// b坐标为(PosX[1], PosY[1])~~如此类推
点1 (x + r*sin36度, y - r*cos36)
2 (x - r*sin36度, y - r*cos36)
3 (x + r*cos36度, y)
4 (x, y + r*cos36度)
5 (x - r*cos36度, y)
看成是一个圆
5个顶点在圆上,
设半径:r=50,圆心:x=100,y=100
则:最上一个顶点坐标为:x1=100,y1=50
左边第二个顶点坐标为:x2= x-50*sin72度,y2=y-50*cos72度
右边第二个顶点坐标为:x3=x+50*sin72度,y3=y-50*cos72度
左边第三个顶点坐标为:x4=x-50*sin36度,y4=y+50*cos36度
右边第三个顶点坐标为:x5=x+50*sin36度,y5=y+50*cos36度ok
几个顶点的坐标就出来了,如下
(x,y-r);(x-r*sin72度,y-r*cos72度);(x+r*sin72度,y-r*cos72度);
(x-r*sin36度,y+r*cos36度);(x+r*sin36度,y+r*cos36度)
求正弦余弦,java中有相应的函数,自己查一下就知道了~
-----------问题解决就给分吧~
// Set the proper points to draw a 5 sided polygon
// These formulas are based on where a point should be
// proportionally relitive to the starting point (x1,y1)
// and the ending point (x,y)
public void plot(int x,int y) {
x_points[0] = (x-x1)/2+x1;
x_points[1] = x;
x_points[2] = (x-x1)*3/4+x1;
x_points[3] = (x-x1)/4+x1;
x_points[4] = x1;
x_points[5] = (x-x1)/2+x1; y_points[0] = y1;
y_points[1] = (y-y1)*7/16+y1;
y_points[2] = y;
y_points[3] = y;
y_points[4] = (y-y1)*7/16+y1;
y_points[5] = y1;
}
应该是
顶点(x,y),半径R
其余四点
(x-sin36*cos36*R,y+sin36*sin36*R)
(x+sin36*cos36*R,y+sin36*sin36*R)
(x-2*sin18*cos18*R,y+2*cos18*cos18*R)
(x+2*sin18*cos18*R,y+2*cos18*cos18*R)
我试了一下,画一个正立的五角星,只有rinehart的算法是对的,其他人的都是斜着的。
不过,rinehart(rinehart) 的的最后两行应该为:
(x-sin18*cos18*R,y+cos18*cos18*R)
(x+sin18*cos18*R,y+cos18*cos18*R)