【问题标题】:Create hexagon with points at top and bottom创建六边形,顶部和底部都有点
【发布时间】:2012-11-05 23:40:09
【问题描述】:

我已经很久没有做过任何几何图形了,我不知道该怎么做。

我创建了这个方法:

public Polygon getHex(int posX, int posY) {
        Polygon hex = new Polygon();
        for (int i = 0; i < 6; i++) {
            hex.addPoint((int) (posX + (50 * Math.cos(i * 2 * Math.PI / 6))),
                    (int) (posY + (50 * Math.sin(i * 2 * Math.PI / 6))));
        }
        return hex;
    }

这样创建一个等边六边形:

  _
 / \
 \_/

我需要一个这样的旋转等边六边形:

   /\
  |  |
   \/ 

谁能帮我记住数学?谢谢

【问题讨论】:

    标签: java awt polygon


    【解决方案1】:

    i * 2 更改为(1 + i * 2),这将使您的所有点旋转 pi/6,这应该可以解决问题!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-02-21
      • 1970-01-01
      • 2012-12-08
      • 1970-01-01
      • 1970-01-01
      • 2015-11-25
      • 1970-01-01
      • 2018-12-17
      相关资源
      最近更新 更多