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

    [​IMG]
    Code:java
    1.  
    2.  
    3. int locX = player.getLocation().getBlockX();
    4. int locY = player.getLocation().getBlockY();
    5. int locZ = player.getLocation().getBlockZ();
    6. int radius = Integer.parseInt(args[0]);
    7. int x, z, r2;
    8.  
    9. r2 = radius * radius;
    10. player.getWorld().getBlockAt(locX,locY, locZ + radius).setType(Material.STONE);
    11. player.getWorld().getBlockAt(locX,locY, locZ - radius).setType(Material.STONE);
    12. for (x = 1; x <= radius; x++) {
    13. z = (int) (Math.sqrt(r2 - x*x) + 0.5);
    14. player.getWorld().getBlockAt(locX + x,locY, locZ + z).setType(Material.STONE);
    15. player.getWorld().getBlockAt(locX + x,locY, locZ - z).setType(Material.STONE);
    16. player.getWorld().getBlockAt(locX - x,locY, locZ + z).setType(Material.STONE);
    17. player.getWorld().getBlockAt(locX - x,locY, locZ - z).setType(Material.STONE);
    18. }
     
  2. Offline

    TomFromCollege

    Code:java
    1. for (int y = startY; y < startY + height; y++) {
    2. if (currentX >= currentZ) {
    3. f = 1 - radius;
    4. ddF_x = 1;
    5. ddF_y = -2 * radius;
    6. currentX = 0;
    7. currentZ = radius;
    8. locations.add(new Location(start.getWorld(), startX, y, startZ + radius));
    9. locations.add(new Location(start.getWorld(), startX, y, startZ - radius));
    10. locations.add(new Location(start.getWorld(), startX + radius, y, startZ));
    11. locations.add(new Location(start.getWorld(), startX - radius, y, startZ));
    12. }
    13. while (currentX < currentZ) {
    14. if (f >= 0) {
    15. currentZ--;
    16. ddF_y += 2;
    17. f += ddF_y;
    18. }
    19. currentX++;
    20. ddF_x += 2;
    21. f += ddF_x;
    22. locations.add(new Location(start.getWorld(), startX + currentX, y, startZ + currentZ));
    23. locations.add(new Location(start.getWorld(), startX - currentX, y, startZ + currentZ));
    24. locations.add(new Location(start.getWorld(), startX + currentX, y, startZ - currentZ));
    25. locations.add(new Location(start.getWorld(), startX - currentX, y, startZ - currentZ));
    26. locations.add(new Location(start.getWorld(), startX + currentZ, y, startZ + currentX));
    27. locations.add(new Location(start.getWorld(), startX - currentZ, y, startZ + currentX));
    28. locations.add(new Location(start.getWorld(), startX + currentZ, y, startZ - currentX));
    29. locations.add(new Location(start.getWorld(), startX - currentZ, y, startZ - currentX));
    30. }
    31. }

    Not a clue about your problem, but here's mine you can rip apart :p
    It was taken from http://en.wikipedia.org/wiki/Midpoint_circle_algorithm
     
    Knaxel likes this.
Thread Status:
Not open for further replies.

Share This Page