Solved circle generation has gaps?

Discussion in 'Plugin Development' started by Knaxel, Apr 26, 2014.

Thread Status:
Not open for further replies.
1. Offline

Knaxel

Code:java
`  int locX = player.getLocation().getBlockX();int locY = player.getLocation().getBlockY();int locZ = player.getLocation().getBlockZ();int radius = Integer.parseInt(args[0]);       int x, z, r2;        r2 = radius * radius;       player.getWorld().getBlockAt(locX,locY, locZ + radius).setType(Material.STONE);       player.getWorld().getBlockAt(locX,locY, locZ - radius).setType(Material.STONE);       for (x = 1; x <= radius; x++) {           z = (int) (Math.sqrt(r2 - x*x) + 0.5);           player.getWorld().getBlockAt(locX + x,locY, locZ + z).setType(Material.STONE);           player.getWorld().getBlockAt(locX + x,locY, locZ - z).setType(Material.STONE);           player.getWorld().getBlockAt(locX - x,locY, locZ + z).setType(Material.STONE);           player.getWorld().getBlockAt(locX - x,locY, locZ - z).setType(Material.STONE);       }`

#1
2. Offline

TomFromCollege

Code:java
`for (int y = startY; y < startY + height; y++) {            if (currentX >= currentZ) {                f = 1 - radius;                ddF_x = 1;                ddF_y = -2 * radius;                currentX = 0;                currentZ = radius;                locations.add(new Location(start.getWorld(), startX, y, startZ + radius));                locations.add(new Location(start.getWorld(), startX, y, startZ - radius));                locations.add(new Location(start.getWorld(), startX + radius, y, startZ));                locations.add(new Location(start.getWorld(), startX - radius, y, startZ));            }            while (currentX < currentZ) {                if (f >= 0) {                    currentZ--;                    ddF_y += 2;                    f += ddF_y;                }                currentX++;                ddF_x += 2;                f += ddF_x;                locations.add(new Location(start.getWorld(), startX + currentX, y, startZ + currentZ));                locations.add(new Location(start.getWorld(), startX - currentX, y, startZ + currentZ));                locations.add(new Location(start.getWorld(), startX + currentX, y, startZ - currentZ));                locations.add(new Location(start.getWorld(), startX - currentX, y, startZ - currentZ));                locations.add(new Location(start.getWorld(), startX + currentZ, y, startZ + currentX));                locations.add(new Location(start.getWorld(), startX - currentZ, y, startZ + currentX));                locations.add(new Location(start.getWorld(), startX + currentZ, y, startZ - currentX));                locations.add(new Location(start.getWorld(), startX - currentZ, y, startZ - currentX));              }        }`

Not a clue about your problem, but here's mine you can rip apart
It was taken from http://en.wikipedia.org/wiki/Midpoint_circle_algorithm

#2
Knaxel likes this.
Thread Status:
Not open for further replies.