读书人

求一画六边形的代码解决方法

发布时间: 2012-01-07 21:41:55 作者: rapoo

求一画六边形的代码
求一画六边形的代码

[解决办法]
SF..不太清楚楼主说的到底什么意思`

[解决办法]
输出到哪?
[解决办法]
用DrawPolygon()方法可以绘制多边形,你只要提供六边形的顶点坐标就行了。
[解决办法]
这种代码网上很多的:

static const float pi = 3.14159265359;

//cos函数和sin函数的参数传递的是弧度,所以要把角度转换成弧度。
//正六边形需要计算的角度。
static const float fcos30 = cos((float)30/180*pi);
static const float fsin30 = sin((float)30/180*pi);

//正五边形和正六边形均需要计算的角度
static const float fcos90 = cos((float)90/180*pi);
static const float fsin90 = sin((float)90/180*pi);

//fR代表“外接圆半径”
//x向右为正(右边),反向为负(左边)
//y向下为正(下边),反向为负(上边)

//正五边形顶点画法
m_point[0].m_fx = fR*fcos18+m_point[8].m_fx;
m_point[0].m_fy = fR*(-fsin18)+m_point[8].m_fy;

m_point[1].m_fx = fR*fcos90+m_point[8].m_fx;
m_point[1].m_fy = fR*(-fsin90)+m_point[8].m_fy;

m_point[2].m_fx = fR*(-fcos18)+m_point[8].m_fx;
m_point[2].m_fy = fR*(-fsin18)+m_point[8].m_fy;

m_point[3].m_fx = fR*(-fcos54)+m_point[8].m_fx;
m_point[3].m_fy = fR*(fsin54)+m_point[8].m_fy;

m_point[4].m_fx = fR*(fcos54)+m_point[8].m_fx;
m_point[4].m_fy = fR*(fsin54)+m_point[8].m_fy;
int iStar = 5;

//正六边形顶点画法
m_point[0].m_fx = fR*fcos30+m_point[8].m_fx;
m_point[0].m_fy = fR*(-fsin30)+m_point[8].m_fy;

m_point[1].m_fx = fR*fcos90+m_point[8].m_fx;
m_point[1].m_fy = fR*(-fsin90)+m_point[8].m_fy;

m_point[2].m_fx = fR*(-fcos30)+m_point[8].m_fx;
m_point[2].m_fy = fR*(-fsin30)+m_point[8].m_fy;

m_point[3].m_fx = fR*(-fcos30)+m_point[8].m_fx;
m_point[3].m_fy = fR*(fsin30)+m_point[8].m_fy;

m_point[4].m_fx = fR*(fcos90)+m_point[8].m_fx;
m_point[4].m_fy = fR*(fsin90)+m_point[8].m_fy;

m_point[5].m_fx = fR*(fcos30)+m_point[8].m_fx;
m_point[5].m_fy = fR*(fsin30)+m_point[8].m_fy;
int iStar = 6;

//伪代码做顶点连线
for (int i=0;i <iStar;++i)
{
line(m_point[8].m_fx,m_point[8].m_fy,m_point[i].m_fx,m_point[i].m_fy);

if (i == (iStar-1))
{
line(m_point[i].m_fx,m_point[i].m_fy,m_point[0].m_fx,m_point[0].m_fy);
return ;
}
else
line(m_point[i].m_fx,m_point[i].m_fy,m_point[i+1].m_fx,m_point[i+1].m_fy);
}


[解决办法]
GDI+
[解决办法]
Dim image As Bitmap = New Bitmap(180, 196)
Dim axesFont As Font = New Font( "arial ", 15, FontStyle.Bold)
Dim blackBrush As Brush = New SolidBrush(Color.Black)
Dim g As Graphics = Graphics.FromImage(image)
Dim redPen As Pen = New Pen(Color.Red, 1)
Dim blackPen As Pen = New Pen(Color.Black, 1)
g.Clear(Color.White)
Dim Dx, Dy, Len, Hg
Dx = 1 : Dy = 1 : Len = 90 : Hg = Math.Sqrt(3) * Len / 2
Dim x1, y1, x2, y2, x3, y3, x4, y4, x5, y5, x6, y6 As Single
x1 = Dx : y1 = Dy - Len : x2 = Dx : y2 = Dy + Len
x3 = Dx - Hg : y3 = Dy - Len / 2 : x4 = Dx + Hg : y4 = Dy + Len / 2
x5 = Dx - Hg : y5 = Dy + Len / 2 : x6 = Dx + Hg : y6 = Dy - Len / 2

x1 += 100 : y1 += 100 : x2 += 100 : y2 += 100 : x3 += 100 : y3 += 100
x4 += 100 : y4 += 100 : x5 += 100 : y5 += 100 : x6 += 100 : y6 += 100

g.DrawLine(blackPen, x3, y3, x1, y1)
g.DrawLine(blackPen, x1, y1, x6, y6)


g.DrawLine(blackPen, x6, y6, x4, y4)
g.DrawLine(blackPen, x4, y4, x2, y2)
g.DrawLine(blackPen, x2, y2, x5, y5)
g.DrawLine(blackPen, x5, y5, x3, y3)
image.Save(Response.OutputStream, ImageFormat.Gif)

读书人网 >asp.net

热点推荐