/** * Tests if the given point is inside this polygon or exactly on and edge/vertex of this polygon. * <p> * Edge cases: * <ul> * <li>if {@code numberOfVertices == 0}, this method returns {@code false}. * <li>if {@code numberOfVertices == 1}, this method returns whether the query and the single * vertex are exactly equal. * <li>if {@code numberOfVertices == 2}, this method returns whether the query is exactly on the * polygons single edge. * </ul> * * @param x the x-coordinate of the query. * @param y the y-coordinate of the query. * @return {@code true} if the query is inside this polygon, {@code false} otherwise. * @throws OutdatedPolygonException if {@link ConvexPolygon2DBasics#update()} has not been called * since last time this polygon's vertices were edited. */ default boolean isPointInside(double x, double y) { return isPointInside(x, y, 0.0); }
/** * Tests if the given point is inside this polygon or exactly on and edge/vertex of this polygon. * <p> * Edge cases: * <ul> * <li>if {@code numberOfVertices == 0}, this method returns {@code false}. * <li>if {@code numberOfVertices == 1}, this method returns whether the query and the single * vertex are exactly equal. * <li>if {@code numberOfVertices == 2}, this method returns whether the query is exactly on the * polygons single edge. * </ul> * * @param point the query. Not modified. * @return {@code true} if the query is inside this polygon, {@code false} otherwise. * @throws OutdatedPolygonException if {@link ConvexPolygon2DBasics#update()} has not been called * since last time this polygon's vertices were edited. */ default boolean isPointInside(Point2DReadOnly point) { return isPointInside(point, 0.0); }
/** * Tests if the given point is inside this polygon or exactly on and edge/vertex of this polygon. * * @param point the query. Not modified. * @return {@code true} if the query is inside this polygon, {@code false} otherwise. * @throws ReferenceFrameMismatchException if {@code point} and {@code this} are not expressed in * the same reference frame. * @see #isPointInside(Point2DReadOnly) */ default boolean isPointInside(FramePoint2DReadOnly point) { checkReferenceFrameMatch(point); return ConvexPolygon2DReadOnly.super.isPointInside(point); }
/** * Determines if the point is inside this convex polygon given the tolerance {@code epsilon}. * * @param point the query. Not modified. * @param epsilon the tolerance to use during the test. * @return {@code true} if the query is considered to be inside the polygon, {@code false} * otherwise. * @throws ReferenceFrameMismatchException if {@code point} and {@code this} are not expressed in * the same reference frame. * @see #isPointInside(Point2DReadOnly, double) */ default boolean isPointInside(FramePoint2DReadOnly point, double epsilon) { checkReferenceFrameMatch(point); return ConvexPolygon2DReadOnly.super.isPointInside(point, epsilon); }
/** * from * http://softsurfer.com/Archive/algorithm_0111/algorithm_0111.htm#Pseudo-Code:%20Clip%20Segment-Polygon * Input: a 2D segment S from point P0 to point P1 a 2D convex polygon W with n vertices * V0,...,Vn-1,Vn=V0 */ public static boolean doesSegmentIntersectConvexPolygon2D(Point2DReadOnly P0, Point2DReadOnly P1, ConvexPolygon2DReadOnly convexPolygon2d) { // if segment is a single point if (P0.equals(P1)) { return convexPolygon2d.isPointInside(P0); } // if either point is inside polygon if (convexPolygon2d.isPointInside(P0, .0001) || convexPolygon2d.isPointInside(P1, .0001)) return true; // if either point touches the polygon if (convexPolygon2d.pointIsOnPerimeter(P0) || convexPolygon2d.pointIsOnPerimeter(P1)) return true; return doesSegmentPassCompletelyThroughPolygon(P0, P1, convexPolygon2d); }
/** * Determines if the polygonToTest is inside the convex polygon. */ public static boolean isPolygonInside(ConvexPolygon2DReadOnly polygonToTest, double epsilon, ConvexPolygon2DReadOnly polygon) { for (int i = 0; i < polygonToTest.getNumberOfVertices(); i++) { if (!polygon.isPointInside(polygonToTest.getVertex(i), epsilon)) return false; } return true; }
if (polygonP.isPointInside(polygonQ.getVertex(0))) if (polygonQ.isPointInside(polygonP.getVertex(0)))