#(Java) Spigot + Math / code for shapes

1 messages · Page 1 of 1 (latest)

stuck apex
#
public static void generateEllipsoid(World world, Location center, int width1, int width2, int depth, Material material) {
            int a = width1 / 2; // horizontal radius
            int b = width2 / 2; // vertical radius
            int c = depth / 2; // depth radius

            for (int x = -a; x <= a; x++) {
                for (int y = -b; y <= b; y++) {
                    for (int z = -c; z <= c; z++) {
                        double distance = ((double) x / a) * ((double) x / a) + ((double) y / b) * ((double) y / b) + ((double) z / c) * ((double) z / c);
                        if (distance <= 1) {
                            Location loc = center.clone().add(x, y, z);
                            world.getBlockAt(loc).setType(material);
                        }
                    }
                }
            }
        }