用VC画五角星的方法

来源:互联网 发布:php函数验证email 编辑:程序博客网 时间:2024/04/28 01:35

     五角星有五个点,通过其中的两个可以确定圆心,由圆心可以找出另外的三个点,只要把这五个点都找全了,运用pDC->MoveTo() ,pDC->LineTo()按一定的点顺序就可以把五角星画出来。

 

//这是在确定五个点的坐标。
  int x1=x0,
      x2=(int)(x0-Math.sin(ch)*r),
      x3=(int)(x0+Math.sin(ch)*r),
      x4=(int)(x0-Math.sin(ch/2)*r),
      x5=(int)(x0+Math.sin(ch/2)*r);
  int y1=y0-r,
      y2=(int)(y0-Math.cos(ch)*r),
      y3=y2,
      y4=(int)(y0+Math.cos(ch/2)*r),
      y5=y4;
//由半径和圆心确定了五个点的坐标

 

  //五角星是中心对称图形,角度的实际取值范围在“0——72”之间;
  int x[]={(int)(x0+Math.sin(de)*r),
           (int)(x0-r*Math.sin(ch-de)),
           (int)(x0+r*Math.cos(de-ch/4)),
           (int)(x0-r*Math.sin(ch/2+de)),
           (int)(x0+r*Math.sin(ch/2-de)),
          };
  int y[]={(int)(y0-r*Math.cos(de)),
           (int)(y0-r*Math.cos(ch-de)),
           (int)(y0+r*Math.sin(de-ch/4)),
           (int)(y0+r*Math.cos(ch/2+de)),
           (int)(y0+r*Math.cos(ch/2-de)),
           }

以上是可能用到的核心代码。

    double de = atan((b2-a2)/(b1-a1));
    double ch = 144*pi/180;

    double de = atan((b2-a2)/(b1-a1));
    double ch = 72*pi/180;
原创粉丝点击