2012-11-14 20 views
1

我需要一个方法来获得圆的点获得点,我有一个,我在网上找到但不幸的是我想添加填充它一个布尔值:的Java:布尔一圈充满

public static Location[] getCylinderAt(Location loc, int r, int height) { 
    ArrayList<Location> list = new ArrayList<>(); 

    int cx = loc.getBlockX(); 
    int cy = loc.getBlockY(); 
    int cz = loc.getBlockZ(); 
    World w = loc.getWorld(); 
    int rSquared = r * r; 

    for (int x = cx - r; x <= cx + r; x++) { 
     for (int y = cy - height; y <= cy + height; y++) { 
      for (int z = cz - r; z <= cz + r; z++) { 
       if ((cx - x) * (cx - x) + (cz - z) * (cz - z) <= rSquared) { 
        list.add(new Location(w, x, y, z)); 
       } 
      } 
     } 
    } 
    return list.toArray(new Location[list.size()]); 
} 

我无法真正理解数学中涉及到的数学问题,并一直在寻找非Minecraft资源来创建我自己的,但无济于事。

理想情况下,我想能够在方法改成这样:

public static Location[] getCylinderAt(Location loc, boolean filled, int r, int height) 

谢谢你们!如果你喜欢,我可以删除所有的Minecraft引用,但我不认为这是必要的,因为一个位置基本上是一个只有几个添加了我的世界唯一变量的Vector!

感谢您的阅读:)

+3

额外参数的目的是什么? –

+0

对不起,为了使阵列只包含外部圆柱体而不是其中的每个点 –

+0

请解释“填充”的概念,您是在圆周上还是在圆盘表面上搜索圆周上的点? – Aubin

回答

2

您是否正在寻找一种方法来计算一个圆的边缘像素,而不是那些内部,对于filledfalse的情况?如果是这样,看看midpoint circle algorithm。它描述了如何在光栅图像中绘制一个圆。

+0

正是我在找的东西,算法向我解释了! :d –