/** * Returns a boolean value, stating whether a 2D point is on the left or right side of this line. * The idea of "side" is determined based on the direction of the line. * <p> * For instance, given the {@code this.direction} components x = 0, and y = 1, and the * {@code this.point} coordinates x = 0, and y = 0, a point located on: * <ul> * <li>the left side of this line has a negative y coordinate. * <li>the right side of this line has a positive y coordinate. * </ul> * </p> * This method will return {@code false} if the point is on this line. * * @param point the coordinates of the query point. * @return {@code true} if the point is on the left side of this line, {@code false} if the point * is on the right side or exactly on this line. * @throws ReferenceFrameMismatchException if {@code this} and {@code point} are not expressed in * the same reference frame. */ default boolean isPointOnLeftSideOfLine(FramePoint2DReadOnly point) { checkReferenceFrameMatch(point); return Line2DReadOnly.super.isPointOnLeftSideOfLine(point); }
/** * Returns a boolean value, stating whether the query point is in front of this line or not. * <p> * The idea of 'front' refers to the side of the line toward which the x-axis is pointing. * </p> * * @param point the coordinates of the query. Not modified. * @return {@code true} if the point is in front of this line, {@code false} if the point is behind * the line. * @throws RuntimeException if the given point is located exactly on this line. */ default boolean isPointInFrontOfLine(Point2DReadOnly point) { if (getDirectionY() > 0.0) return isPointOnRightSideOfLine(point); else if (getDirectionY() < 0.0) return isPointOnLeftSideOfLine(point); else throw new RuntimeException("Not defined when line is pointing exactly along the x-axis"); }
/** * Returns a boolean value, stating whether the query point is in front of this line or not. * <p> * The idea of 'front' refers to the side of the line toward which the given vector * {@code frontDirection} is pointing. * </p> * * @param frontDirection the vector used to define the side of the line which is to be considered as * the front. Not modified. * @param point the coordinates of the query. Not modified. * @return {@code true} if the point is in front of this line, {@code false} if the point is behind * the line. * @throws RuntimeException if the given point is located exactly on this line. */ default boolean isPointInFrontOfLine(Vector2DReadOnly frontDirection, Point2DReadOnly point) { double crossProduct = frontDirection.cross(getDirection()); if (crossProduct > 0.0) return isPointOnRightSideOfLine(point); else if (crossProduct < 0.0) return isPointOnLeftSideOfLine(point); else throw new RuntimeException("Not defined when line is pointing exactly along the front direction"); }