# Efficient way to check if a location is within a cuboid zone (defined by two other locs)

Discussion in 'Plugin Development' started by captainawesome7, Aug 16, 2011.

Not open for further replies.
1. Offline

### captainawesome7

Basically I failed at coming up with a Boolean method that checks to see if the location is "within" the other two.
Code:
```public Boolean isInside(Location loc, Location corner1, Location corner2) {
//If loc is "inside" the cuboid region defined by the two corner locations, return true

}```
I know that I could loop through it, checking if any location is equal to loc, but that would be terrible, right?

2. Offline

Thats how I would go about it (written down in Notepad++ in several minutes, so it may include some errors, but well I think you get what I mean ):

Code:java
`public Boolean isInside(Location loc, Location corner1, Location corner2) {    double xMin = 0;    double xMax = 0;    double yMin = 0;    double yMax = 0;    double zMin = 0;    double zMax = 0;    double x = loc.getX();    double y = loc.getY();    double z = loc.getZ();     xMin = Math.min(corner1.getX(), corner2.getX());    xMax = Math.max(corner1.getX(), corner2.getX());     yMin = Math.min(corner1.getY(), corner2.getY());    yMax = Math.max(corner1.getY(), corner2.getY());     zMin = Math.min(corner1.getZ(), corner2.getZ());    zMax = Math.max(corner1.getZ(), corner2.getZ());     return (x >= xMin && x <= xMax && y >= yMin && y <= yMax && z >= zMin && z <= zMax);}`

#2
3. Offline

### captainawesome7

Looks good, I'll try it out.