/** * Determines whether an observer can see the outside of the given edge. The edge index corresponds to * the vertex at the start of the edge when moving clockwise around the polygon. Will return false if the * observer is on the edge. */ public static boolean canObserverSeeEdge(int edgeIndex, Point2d observer, ConvexPolygon2d polygon) { return canObserverSeeEdge(edgeIndex, observer.x, observer.y, polygon); }
boolean edgeVisible = ConvexPolygon2dCalculator.canObserverSeeEdge(numberOfVertices - 1, observer, polygon); int foundCorners = 0; for (int i = 0; i < numberOfVertices; i++) boolean nextEdgeVisible = ConvexPolygon2dCalculator.canObserverSeeEdge(i, observer, polygon); if (edgeVisible && !nextEdgeVisible)
double distanceToEdgeLine = GeometryTools.distanceFromPointToLine(pointX, pointY, edgeStart.x, edgeStart.y, edgeEnd.x - edgeStart.x, edgeEnd.y - edgeStart.y); boolean pointOutside = canObserverSeeEdge(i, pointX, pointY, polygon); if (!pointOutside) distanceToEdgeLine = -distanceToEdgeLine;