/**
创建一个五角星形状.
该五角星的中心坐标为(sx,sy),中心到顶点的距离为radius,其中某个顶点与中心的连线的偏移角度为theta(弧度)
@return pentacle 一个☆
*/
public static Shape createPentacle(double sx,double sy,double radius,double theta){
final double arc = Math.PI/5;
final double rad = Math.sin(Math.PI/10)/Math.sin(3*Math.PI/10);
GeneralPath path = new GeneralPath();
path.moveTo(1,0);
for(int idx = 0;idx < 5;idx ++){
path.lineTo(rad*Math.cos((1+2*idx)*arc),rad*Math.sin((1+2*idx)*arc));
path.lineTo(Math.cos(2*(idx+1)*arc),Math.sin(2*(idx+1)*arc));
}
path.closePath();
AffineTransform atf = AffineTransform.getScaleInstance(radius,radius);
atf.translate(sx/radius,sy/radius);
atf.rotate(theta);
return atf.createTransformedShape(path);
}如上代码所示,数学功底不好凸显了,很苦恼,求帮助。
创建一个五角星形状.
该五角星的中心坐标为(sx,sy),中心到顶点的距离为radius,其中某个顶点与中心的连线的偏移角度为theta(弧度)
@return pentacle 一个☆
*/
public static Shape createPentacle(double sx,double sy,double radius,double theta){
final double arc = Math.PI/5;
final double rad = Math.sin(Math.PI/10)/Math.sin(3*Math.PI/10);
GeneralPath path = new GeneralPath();
path.moveTo(1,0);
for(int idx = 0;idx < 5;idx ++){
path.lineTo(rad*Math.cos((1+2*idx)*arc),rad*Math.sin((1+2*idx)*arc));
path.lineTo(Math.cos(2*(idx+1)*arc),Math.sin(2*(idx+1)*arc));
}
path.closePath();
AffineTransform atf = AffineTransform.getScaleInstance(radius,radius);
atf.translate(sx/radius,sy/radius);
atf.rotate(theta);
return atf.createTransformedShape(path);
}如上代码所示,数学功底不好凸显了,很苦恼,求帮助。
解决方案 »
- 菜鸟求助啊!!
- JDialog中对话框关闭事件
- 如何用JAVA程序调用其他的JAVA程序
- 一个棘手的java字符串"1110100101010010"的问题
- DB2中使用moveToInsertRow()出错,为什么?
- java 用swing制作下拉按钮
- webstart程序,都通过什么方式和别的程序通信的?
- 请问在java中有没有一个用来显示字符串用的二维表的类呀,象JTable一样,不过要带滚动条的.
- only instances of classes are subject to garbage collection not primitives.怎么翻译?
- 【求助】Eclipse application项目选项卡的问题
- java中用集合添加菜单栏选项怎么样注册事件功能
- 朋友去应聘遇到的一个面试的题目
该五角星的中心坐标为(sx,sy),中心到顶点的距离为radius,其中某个顶点与中心的连线的偏移角度为theta(弧度)
说的这么清楚了还不明白吗?
LZ应该是语文功底不好吧.......汗.
一个点,确定了五角星的中心位置
距离确定了五角星的大小
偏移角度确定了五角星的方向
final double arc = Math.PI/5;
final double rad = Math.sin(Math.PI/10)/Math.sin(3*Math.PI/10);
GeneralPath path = new GeneralPath();
path.moveTo(1,0);
for(int idx = 0;idx < 5;idx ++){
path.lineTo(rad*Math.cos((1+2*idx)*arc),rad*Math.sin((1+2*idx)*arc));
path.lineTo(Math.cos(2*(idx+1)*arc),Math.sin(2*(idx+1)*arc));
}
这段的含义。