public final F createFrameConvexPolygon2D(F frameConvexPolygon2D) { return createFrameConvexPolygon2D(frameConvexPolygon2D.getReferenceFrame(), frameConvexPolygon2D.getVertexBufferView().subList(0, frameConvexPolygon2D.getNumberOfVertices())); }
/** * Computes the coordinates of the possible intersection(s) between a given line segment 2D and * this convex polygon 2D. * * @param lineSegment2D the line segment that may intersect this polygon. Not modified. * @return the intersections between the line segment and the polygon. * @throws ReferenceFrameMismatchException if {@code lineSegment2D} and {@code this} are not * expressed in the same reference frame. * @see #intersectionWith(LineSegment2DReadOnly) */ default FramePoint2DBasics[] intersectionWith(FrameLineSegment2DReadOnly lineSegment2D) { checkReferenceFrameMatch(lineSegment2D); return intersectionWith((LineSegment2DReadOnly) lineSegment2D); }
/** * Adds a subset of this polygon's vertices into the given list. * * @param startIndexInclusive the index of the first vertex to add. * @param endIndexInclusive the index of the last vertex to add. * @param pointListToPack the list into which the vertices are to be added. * @see #getPointsInClockwiseOrder(int, int, List) */ default void getFramePointsInClockwiseOrder(int startIndexInclusive, int endIndexInclusive, List<FramePoint2DReadOnly> pointListToPack) { checkIfUpToDate(); checkIndexInBoundaries(startIndexInclusive); checkIndexInBoundaries(endIndexInclusive); int index = startIndexInclusive; while (true) { pointListToPack.add(getVertex(index)); if (index == endIndexInclusive) break; index = getNextVertexIndex(index); } }
/** * Computes the orthogonal projection of a 2D point on this 2D convex polygon. * * @param pointToProject the coordinate of the point to compute the projection of. Not modified. * @return the coordinates of the projection, or {@code null} if the method failed. * @throws ReferenceFrameMismatchException if {@code pointToProject} and {@code this} are not * expressed in the same reference frame. * @see #orthogonalProjectionCopy(Point2DReadOnly) */ default FramePoint2DBasics orthogonalProjectionCopy(FramePoint2DReadOnly pointToProject) { checkReferenceFrameMatch(pointToProject); return orthogonalProjectionCopy((Point2DReadOnly) pointToProject); }
/** * Finds the index of the closest vertex to the query. * * @param point the coordinates of the query. Not modified. * @return the coordinates of the closest vertex, or {@code null} if this method failed. * @throws ReferenceFrameMismatchException if {@code point} and {@code this} are not expressed in * the same reference frame. * @see #getClosestVertexCopy(Point2DReadOnly) */ default FramePoint2DBasics getClosestVertexCopy(FramePoint2DReadOnly point) { checkReferenceFrameMatch(point); return getClosestVertexCopy((Point2DReadOnly) point); }
/** * Finds the index of the closest edge to the query. * * @param point the coordinates of the query. Not modified. * @return the line segment representing the closest edge or {@code null} if this method failed. * @throws ReferenceFrameMismatchException if {@code point} and {@code this} are not expressed in * the same reference frame. * @see #getClosestEdgeCopy(Point2DReadOnly) */ default FrameLineSegment2DBasics getClosestEdgeCopy(FramePoint2DReadOnly point) { checkReferenceFrameMatch(point); return getClosestEdgeCopy((Point2DReadOnly) point); }
/** * Tests on a per vertex and per component basis, if this polygon is exactly equal to * {@code other}. * * @param other the other polygon to compare against this. Not modified. * @return {@code true} if the two polygons are exactly equal component-wise and expressed in the * same frame reference frame, {@code false} otherwise. * @see #equals(ConvexPolygon2DReadOnly) */ default boolean equals(FrameConvexPolygon2DReadOnly other) { if (other == null || getReferenceFrame() != other.getReferenceFrame()) return false; else return ConvexPolygon2DReadOnly.super.equals(other); }
/** * Finds the index of the closest edge to the query. * * @param point the coordinates of the query. Not modified. * @param closestEdgeToPack the line segment used to store the result. Not modified. * @return whether this method succeeded or not. * @throws ReferenceFrameMismatchException if {@code point} and {@code this} are not expressed in * the same reference frame. * @see #getClosestEdge(Point2DReadOnly, LineSegment2DBasics) */ default boolean getClosestEdge(FramePoint2DReadOnly point, FrameLineSegment2DBasics closestEdgeToPack) { checkReferenceFrameMatch(point); closestEdgeToPack.setReferenceFrame(getReferenceFrame()); return ConvexPolygon2DReadOnly.super.getClosestEdge(point, closestEdgeToPack); }
/** {@inheritDoc} */ @Override default List<? extends FramePoint2DReadOnly> getPolygonVerticesView() { return getVertexBufferView().subList(0, getNumberOfVertices()); }
/** * Finds the index of the closest edge to the query. * * @param point the coordinates of the query. Not modified. * @param closestEdgeToPack the line segment used to store the result. Not modified. * @return whether this method succeeded or not. * @throws ReferenceFrameMismatchException if {@code point}, {@code closestEdgetoPack}, and * {@code this} are not expressed in the same reference frame. * @see #getClosestEdge(Point2DReadOnly, LineSegment2DBasics) */ default boolean getClosestEdge(FramePoint2DReadOnly point, FixedFrameLineSegment2DBasics closestEdgeToPack) { checkReferenceFrameMatch(point); checkReferenceFrameMatch(closestEdgeToPack); return ConvexPolygon2DReadOnly.super.getClosestEdge(point, closestEdgeToPack); }
public static boolean doesLineIntersectPolygon(FrameConvexPolygon2DReadOnly polygon, FrameLine2DReadOnly line) { boolean onLeft = line.isPointOnLeftSideOfLine(polygon.getVertex(0)); for (int i = 0; i < polygon.getNumberOfVertices(); i++) { if (onLeft != line.isPointOnLeftSideOfLine(polygon.getVertex(i))) { return true; } } return false; }
public void intersectWithLine(FrameConvexPolygon2DReadOnly frameConvexPolygon2d, FrameLine2DReadOnly frameLine2d) { checkAndSetFrames(frameConvexPolygon2d, frameLine2d); int intersectionTypeInt = frameConvexPolygon2d.intersectionWith(frameLine2d, intersectionPointOne, intersectionPointTwo); packIntersectionType(intersectionTypeInt); }
/** * Copies this polygon, translates the copy, and returns it. * * @param translation the translation to apply to the copy of this polygon. Not modified. * @return the copy of this polygon translated. * @throws ReferenceFrameMismatchException if {@code translation} and {@code this} are not * expressed in the same reference frame. * @see #translateCopy(Tuple2DReadOnly) */ default FrameConvexPolygon2DBasics translateCopy(FrameTuple2DReadOnly translation) { checkReferenceFrameMatch(translation); return translateCopy((Tuple2DReadOnly) translation); }
/** * Computes the coordinates of the closest point to the ray that belongs to this convex polygon. * * @param ray the ray to find the closest point to. Not modified. * @return the coordinates of the closest point if the method succeeds, {@code null} otherwise. * @throws ReferenceFrameMismatchException if {@code ray} and {@code this} are not expressed in * the same reference frame. * @see #getClosestPointWithRay(Line2DReadOnly) */ default FramePoint2DBasics getClosestPointWithRay(FrameLine2DReadOnly ray) { checkReferenceFrameMatch(ray); return getClosestPointWithRay((Line2DReadOnly) ray); }
/** * Computes the coordinates of the possible intersection(s) between a given ray 2D and this * convex polygon 2D. * * @param ray the ray that may intersect this polygon. Not modified. * @return the intersections between the ray and the polygon. * @throws ReferenceFrameMismatchException if {@code ray} and {@code this} are not expressed in * the same reference frame. * @see #intersectionWithRay(Line2DReadOnly) */ default FramePoint2DBasics[] intersectionWithRay(FrameLine2DReadOnly ray) { checkReferenceFrameMatch(ray); return intersectionWithRay((Line2DReadOnly) ray); }
/** * From the point of view of an observer located outside the polygon, only a continuous subset of * the polygon's edges can be seen defining a line-of-sight. This method finds the last vertex * that is in the line-of-sight. * * @param observer the coordinates of the observer. Not modified. * @return the coordinates of the last vertex in the line-of-sight or {@code null} if this method * failed. Modified. * @throws ReferenceFrameMismatchException if {@code observer} and {@code this} are not expressed * in the same reference frame. * @see #lineOfSightEndVertexCopy(Point2DReadOnly) */ default FramePoint2DBasics lineOfSightEndVertexCopy(FramePoint2DReadOnly observer) { checkReferenceFrameMatch(observer); return lineOfSightEndVertexCopy((Point2DReadOnly) observer); }
/** * From the point of view of an observer located outside the polygon, only a continuous subset of * the polygon's edges can be seen defining a line-of-sight. This method finds the first vertex * that is in the line-of-sight. * * @param observer the coordinates of the observer. Not modified. * @return the coordinates of the first vertex in the line-of-sight or {@code null} if this * method failed. Modified. * @throws ReferenceFrameMismatchException if {@code observer} and {@code this} are not expressed * in the same reference frame. * @see #lineOfSightStartVertexCopy(Point2DReadOnly) */ default FramePoint2DBasics lineOfSightStartVertexCopy(FramePoint2DReadOnly observer) { checkReferenceFrameMatch(observer); return lineOfSightStartVertexCopy((Point2DReadOnly) observer); }
/** * From the point of view of an observer located outside the polygon, only a continuous subset of * the polygon's edges can be seen defining a line-of-sight. This method finds the first and last * vertices that is in the line-of-sight. * * @param observer the coordinates of the observer. Not modified. * @return the coordinates in order of the first and last vertices in the line-of-sight or * {@code null} if this method failed. Modified. * @throws ReferenceFrameMismatchException if {@code observer} and {@code this} are not expressed * in the same reference frame. * @see #lineOfSightVertices(Point2DReadOnly) */ default FramePoint2DBasics[] lineOfSightVertices(FramePoint2DReadOnly observer) { checkReferenceFrameMatch(observer); return lineOfSightVertices((Point2DReadOnly) observer); }
private static void verifyPointsAreOnPolygon(FramePoint2DReadOnly[] intersectingPoints, FrameConvexPolygon2DReadOnly polygon) { for (FramePoint2DReadOnly point : intersectingPoints) { if (polygon.distance(point) > 1e-10) throw new RuntimeException("Point is not on polygon. Point = " + point); } }
/** * Tests on a per-component basis on every vertices if this convex polygon is equal to * {@code other} with the tolerance {@code epsilon}. * <p> * The method returns {@code false} if the two polygons have different size. * </p> * <p> * The method returns {@code false} if the two polygons are expressed in different frames. * </p> * * @param other the query. Not modified. * @param epsilon the tolerance to use. * @return {@code true} if the two line segments are equal, {@code false} otherwise. * @see #epsilonEquals(ConvexPolygon2DReadOnly, double) */ default boolean epsilonEquals(FrameConvexPolygon2DReadOnly other, double epsilon) { if (getReferenceFrame() != other.getReferenceFrame()) return false; else return ConvexPolygon2DReadOnly.super.epsilonEquals(other, epsilon); }