我需要一种方法来获取圆的点,我在网上找到了一个方法,但不幸的是我想向其中添加一个 boolean 值:
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()]);
}
我无法真正理解其中涉及的数学,并且一直在搜索非《我的世界》资源以创建我自己的资源,但无济于事。
理想情况下,我希望能够将方法更改为:
public static Location[] getCylinderAt(Location loc, boolean filled, int r, int height)
谢谢大家!如果您愿意,我可以删除所有《我的世界》引用,但我认为没有必要,因为位置基本上是一个带有一些仅添加《我的世界》变量的 vector !
感谢您的阅读:)
最佳答案
对于 filled
为 false
的情况,您是否正在寻找一种方法来计算圆边缘上的像素(而不是内部像素)?如果是这样,请查看 midpoint circle algorithm 。它描述了如何在光栅图像中绘制圆。
关于Java:获取填充了 boolean 值的圆的点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13387840/