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-12  เมท็อดวาดรูปสามเหลี่ยมด้านเท่า
  public static void drawEquilateralTriangle(DWindow w,  
                           int xc, int yc, int d, int a) {
    double r = d / (2 * cos(30));
    double angle = a - 30;
    double x0 = xc + r * cos(angle);
    double y0 = yc - r * sin(angle);
    for (int i = 0; i < 3; i++) {
      angle = angle + 120;
      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