五角星的画法
繪制五角星作為GDI+畫圖的一個示例
這是從網上找的比較簡單的方法
http://topic.csdn.net/t/20031128/09/2503872.html
http://it.china-b.com/cxsj/VBNET/20090608/55423_1.html
?void ? MyDraw(Graphics ? g,Point ? center,int ? radius){
? ? Point[] ? pts ? = ? new ? Point[5];
? ? //獲取五角星5個頂點
? ? pts[0] ? = ? new ? Point(center.X,center.Y ? - ? radius);
? ? pts[1] ? = ? Rotate72(pts[0],center);
? ? pts[2] ? = ? Rotate72(pts[1],center);
? ? pts[3] ? = ? Rotate72(pts[2],center);
? ? pts[4] ? = ? Rotate72(pts[3],center);?
??? //簡單地拉5條線
? ? Pen ? pen ? = ? new ? Pen(new ? SolidBrush(Color.Blue));?
??? g.DrawPolygon(....); //空心
??? g.FillPolygon(....); //實心
}
//旋轉72
private ? Point ? Rotate72(Point ? pt,Point ? center){
? ? int ? x ? = ? (int)(center.X ? + ? (pt.X ? - ? center.X) ? * ? Math.Cos(72.0 ? * ? Math.PI/180) ? - ? (pt.Y ? - ? center.Y) ? * ? Math.Sin(72.0 ? * ? Math.PI/180)),
? ? ? ? ? ? y ? = ? (int)(center.Y ? + ? (pt.X ? - ? center.X) ? * ? Math.Sin(72.0 ? * ? Math.PI/180) ? + ? (pt.Y ? - ? center.Y) ? * ? Math.Cos(72.0 ? * ? Math.PI/180));
? ? ? ? return ? new ? Point(x,y); ?
}
//計算內五邊形畫空心五角星
今天畫五角星的時候,發現老是出現交叉線,無法畫空心的,
找了半天沒發現好用的方法,只好自己畫幾何圖形求解了。
以下是數學公式
a/R=sin72;
y/R=cos72;
x/c=sin36;
y/c=con36;
?
可以求了正五角形的第一個角點,再旋轉72度,可以求出其它幾個角點;
然后將這十個點合理排序就是要畫的正五角形。
?
????? 這里的旋轉方法是畫圖的關鍵,其實這里的用的GDI+功能卻不多,不過在gis中被要求畫個五角星之類復雜圖形卻很常見,想想當年三角函數那塊,現在終于用上了。
總結
- 上一篇: 手把手:用OpenCV亲手给小扎、Mus
- 下一篇: 手把手教你开发App(HelloWorl