/** * Takes a point and the corners of a rectangle and returns the two corners representing the side * of the rectangle closest to the point. * * @param point the point which is being checked * @param corners the corners of the rectangle * @return two corners representing the side of the rectangle */ public static float[] closestSide(float[] point, float[] corners) { int len = corners.length; float oldMag = Float.POSITIVE_INFINITY; float[] bestLine = null; for (int i = 0; i < len; i += 2) { float[] line = { corners[i], corners[(i + 1) % len], corners[(i + 2) % len], corners[(i + 3) % len] }; float mag = GeometryMathUtils.vectorLength( GeometryMathUtils.shortestVectorFromPointToLine(point, line)); if (mag < oldMag) { oldMag = mag; bestLine = line; } } return bestLine; }