Look one post down, this one wasn't correctable. (A bug happened..) First at all, you need: Code: World w; int minX, minY, minZ, maxX, maxY, maxZ; Compact Methods for each "size" Code: public int getX() { return maxX - minX + 1; } public int getY() { return maxY - minY + 1; } public int getZ() { return maxZ - minZ + 1; } Check if a location is inside two points Code: public boolean isInside(Location loc) { if (loc.getWorld() != w) return false; if ((loc.getBlockX() >= minX) && (loc.getBlockX() <= maxX) && (loc.getBlockY() >= minY) && (loc.getBlockY() <= maxY) && (loc.getBlockZ() >= minZ) && (loc.getBlockZ() <= maxZ)) { return true; } return false; } Get almost exactly center of a region Code: public Location getCenter() { int x1 = maxX + 1; int y1 = maxY + 1; int z1 = maxZ + 1; return new Location(w, minX + (x1 - minX) / 2.0D, minY + (y1 - minY) / 2.0D, minZ + (z1 - minZ) / 2.0D); } Get the surface (2D) of a region Code: public int getSurface() { return getX() * getZ(); } Get volume Code: public int getVolume() { return getX() * getY() * getZ(); } Will be continued soon.. EDIT by Moderator: merged posts, please use the edit button instead of double posting.
This is pretty basic stuff, but along the same lines... Code: //c is sphere center public static boolean isInsideSphere(Location l, Location c, double radius){ return l.distanceSquared(c)<(radius*radius); } (this is untested, but i did the math out and it should work...) Code: /** * @param l The point to test * @param c1 Axis point 1 * @param c2 Axis point 2 * @param radius The radius * @return If it is inside the cylinder * * for multiple usage, precompute lensq and radsq */ boolean isInsideCylinder(Location l, Location c1, Location c2, double radius){ double lensq = c1.distanceSquared(c2); double radsq = radius*radius; //vec from c1 to c2 Location d = c2.subtract(c1); //vec from c1 to l Location d2 = l.subtract(c1); double dot = d2.getX()*d.getX() + d2.getY()*d.getY() + d2.getZ()*d.getZ(); if(dot<0 || dot>lensq){ return false; } else{ return ((d2.getX()*d2.getX() + d2.getY()*d2.getY() + d2.getZ()*d2.getZ()) - dot*dot/lensq) <= radsq; } }
I know this is just basic Math, but some guys in these "business" aren't able to calculate There are so many threads out there with the title "How to check if a block/player is inside a region". Even simple things can help.