/** * Gets the closest horizontal direction from the given vector. If the * vector is the 0-Vector (ignoring y), this method returns {@link #NONE}. * If the vector is halfway between two directions the clockwise next will * be selected. * * @param vector The vector to convert to a direction * @return The closest horizontal direction. */ public static Direction getClosestHorizontal(Vector3d vector) { return getClosestHorizontal(vector, Division.SECONDARY_ORDINAL); }
/** * Gets the closest direction from the given vector. If the vector is the * 0-Vector, this method returns {@link #NONE}. If the vector has the same * horizontal and vertical length, a horizontal direction will be returned. * If the vector is halfway between two directions the clockwise next will * be selected. * * @param vector The vector to convert to a direction * @param smallestDivision The smallest compass division that can be * returned * @return The closest horizontal direction. */ public static Direction getClosest(Vector3d vector, Division smallestDivision) { if (vector.getY() * vector.getY() <= vector.getX() * vector.getX() + vector.getZ() * vector.getZ()) { return getClosestHorizontal(vector, smallestDivision); } else if (vector.getY() > 0) { return UP; } else { return DOWN; } }
/** * Gets the closest horizontal direction from the given vector. If the * vector is the 0-Vector (ignoring y), this method returns {@link #NONE}. * If the vector is halfway between two directions the clockwise next will * be selected. * * @param vector The vector to convert to a direction * @return The closest horizontal direction. */ public static Direction getClosestHorizontal(Vector3d vector) { return getClosestHorizontal(vector, Division.SECONDARY_ORDINAL); }
/** * Gets the closest direction from the given vector. If the vector is the * 0-Vector, this method returns {@link #NONE}. If the vector has the same * horizontal and vertical length, a horizontal direction will be returned. * If the vector is halfway between two directions the clockwise next will * be selected. * * @param vector The vector to convert to a direction * @param smallestDivision The smallest compass division that can be returned * @return The closest horizontal direction. */ public static Direction getClosest(Vector3d vector, Division smallestDivision) { if (vector.getY() * vector.getY() <= vector.getX() * vector.getX() + vector.getZ() * vector.getZ()) { return getClosestHorizontal(vector, smallestDivision); } else if (vector.getY() > 0) { return UP; } else { return DOWN; } }