6. แยกย่อย

The Camtasia Studio video content presented here requires JavaScript to be enabled and the latest version of the Macromedia Flash Player. If you are you using a browser with JavaScript disabled please enable it now. Otherwise, please update your version of the free Flash Player by downloading here.

 
รหัสที่ 6-13  เมท็อดวาดรูปหลายเหลี่ยมด้านเท่า
  public static void drawEquilateralPolygon(DWindow w,  
                           int xc, int yc, int d, int a, int n) {
    double b = (180 - 360.0/n) / 2;
    double r = d / (2 * cos(b));
    double angle = a - b;
    double x0 = xc + r * cos(angle);
    double y0 = yc - r * sin(angle);
    for (int i = 0; i < n; i++) {
      angle = angle + 360.0/n;
      double x1 = xc + r * cos(angle);
      double y1 = yc - r * sin(angle);
      w.drawLine(x0, y0, x1, y1);
      x0 = x1; y0 = y1;
    }
  }
}
©2009 S.Prasitjutrakul