If my calculations are correct, this should return points of a circle in the minecraft world. The higher the amount, the more accurate your results will be. eg. If you enter 3 for the amount you'll probably end up with 3 points drawing a triangle. If you put 100 you'll come pretty close to a circle in minecraft (depends on the radius ofcourse). Note: the points are drawn on the XZ plane. Code:java public ArrayList<Location> getCircle(Location center, double radius, int amount){ World world = center.getWorld(); double increment = (2*Math.PI)/amount; ArrayList<Location> locations = new ArrayList<Location>(); for(int i = 0;i < amount; i++){ double angle = i*increment; double x = center.getX() + (radius * Math.cos(angle)); double z = center.getZ() + (radius * Math.sin(angle)); locations.add(new Location(world, x, center.getY(), z)); } return locations; }
Cool Could you add a 3d feature? Ivan Oh, and could you add something that adds a pitch that always looks away from the center? That would be AWESOME EDIT by Moderator: merged posts, please use the edit button instead of double posting.
Ivan So Ivan, you can add the sphere method from chasechocolate. So you can make a sphere and a circle. But be sure to use the correct way of reffering to chasechocolate like we learned it on school today!
I ported some methods from worledit Cylinder Code:java public List<Location> getCylinder(Location location, double radiusX, double radiusZ, int height, boolean filled) {Vector pos = location.toVector();World world = location.getWorld();List<Location> blocks = new ArrayList<Location>();radiusX += 0.5;radiusZ += 0.5; if (height == 0) {return blocks;} else if (height < 0) {height = -height;pos = pos.subtract(new Vector(0, height, 0));} if (pos.getBlockY() < 0) {pos = pos.setY(0);} else if (pos.getBlockY() + height - 1 > world.getMaxHeight()) {height = world.getMaxHeight() - pos.getBlockY() + 1;} final double invRadiusX = 1 / radiusX;final double invRadiusZ = 1 / radiusZ; final int ceilRadiusX = (int) Math.ceil(radiusX);final int ceilRadiusZ = (int) Math.ceil(radiusZ); double nextXn = 0;forX: for (int x = 0; x <= ceilRadiusX; ++x) {final double xn = nextXn;nextXn = (x + 1) * invRadiusX;double nextZn = 0;forZ: for (int z = 0; z <= ceilRadiusZ; ++z) {final double zn = nextZn;nextZn = (z + 1) * invRadiusZ; double distanceSq = lengthSq(xn, zn);if (distanceSq > 1) {if (z == 0) {break forX;}break forZ;} if (!filled) {if (lengthSq(nextXn, zn) <= 1 && lengthSq(xn, nextZn) <= 1) {continue;}} for (int y = 0; y < height; ++y) { blocks.add(pos.add(new Vector(x,y,z)).toLocation(world));blocks.add(pos.add(new Vector(-x, y, z)).toLocation(world));blocks.add(pos.add(new Vector(x,y,-z)).toLocation(world));blocks.add(pos.add(new Vector(-x,y,-z)).toLocation(world));}}} return blocks;} Sphere: Code:java public List<Location> getSphere(Location location, double radiusX, double radiusY, double radiusZ, boolean filled){Vector pos = location.toVector();World world = location.getWorld();List<Location> blocks = new ArrayList<Location>(); radiusX += 0.5;radiusY += 0.5;radiusZ += 0.5; final double invRadiusX = 1 / radiusX;final double invRadiusY = 1 / radiusY;final double invRadiusZ = 1 / radiusZ; final int ceilRadiusX = (int) Math.ceil(radiusX);final int ceilRadiusY = (int) Math.ceil(radiusY);final int ceilRadiusZ = (int) Math.ceil(radiusZ); double nextXn = 0;forX: for (int x = 0; x <= ceilRadiusX; ++x) {final double xn = nextXn;nextXn = (x + 1) * invRadiusX;double nextYn = 0;forY: for (int y = 0; y <= ceilRadiusY; ++y) {final double yn = nextYn;nextYn = (y + 1) * invRadiusY;double nextZn = 0;forZ: for (int z = 0; z <= ceilRadiusZ; ++z) {final double zn = nextZn;nextZn = (z + 1) * invRadiusZ; double distanceSq = lengthSq(xn, yn, zn);if (distanceSq > 1) {if (z == 0) {if (y == 0) {break forX;}break forY;}break forZ;} if (!filled) {if (lengthSq(nextXn, yn, zn) <= 1 && lengthSq(xn, nextYn, zn) <= 1 && lengthSq(xn, yn, nextZn) <= 1) {continue;}} blocks.add(pos.add(new Vector(x,y,z)).toLocation(world));blocks.add(pos.add(new Vector(-x,y,z)).toLocation(world));blocks.add(pos.add(new Vector(x,-y,z)).toLocation(world));blocks.add(pos.add(new Vector(x,y,-z)).toLocation(world));blocks.add(pos.add(new Vector(-x,-y,z)).toLocation(world));blocks.add(pos.add(new Vector(x,-y,-z)).toLocation(world));blocks.add(pos.add(new Vector(-x,y,-z)).toLocation(world));blocks.add(pos.add(new Vector(-x,-y,-z)).toLocation(world));}}} return blocks;} These methods are required: Code:java private static final double lengthSq(double x, double y, double z) { return (x * x) + (y * y) + (z * z); } private static final double lengthSq(double x, double z) { return (x * x) + (z * z); }
Ivan Circles in Minecraft? Blasphemy! Nice job, this looks a lot more efficient than my current method
Here were the utils I made https://gist.github.com/Cybermaxke/6800852 It also supports shapes, like triangles, pentagons, etc. I didn't add cylinders yet.
Erm, this may seem like a bit of a silly question, but how would I use this to create flame particles travelling around in a circle? I'm using the ParticleEffect library by DarkBlade12 to create my particles. ( ParticleEffect.FLAME.display(p.getLocation(), 16, 0, 0, 0, 0.0F, 1); )
ItzHectik Code:java final ArrayList<Location> blocks = getCircle(player.getLocation(), 10, 100); new BukkitRunnable() { int loop = 0; @Override public void run() { if (loop >= blocks.size()) { loop = 0; } Particles.FLAME.display(blocks.get(loop++),0, 0, 0, 0, 10); } }.runTaskTimer(this, 0L, 1L); And just for fun (broke physics): Code:java new BukkitRunnable() { @Override public void run() { for (Location location : blocks) { Particles.FLAME.display(location, 0, 0 ,0, 0,1); } } }.runTaskTimer(this, 0L, 1L);