/** * Compares {@code this} to {@code other} to determine if the two lines are geometrically similar. * <p> * Two lines are considered geometrically equal is they are collinear, pointing toward the same or * opposite direction. * </p> * * @param other the line to compare to. Not modified. * @param epsilon the tolerance of the comparison. * @return {@code true} if the two lines represent the same geometry, {@code false} otherwise. * @throws ReferenceFrameMismatchException if {@code this} and {@code other} are not expressed in * the same reference frame. */ default boolean geometricallyEquals(FrameLineSegment3DReadOnly other, double epsilon) { checkReferenceFrameMatch(other); return LineSegment3DReadOnly.super.geometricallyEquals(other, epsilon); }
/** * Computes the vector going from the first to the second endpoint of this line segment. * * @param normalize whether the direction vector is to be normalized. * @param directionToPack vector in which the direction is stored. Modified. * @throws ReferenceFrameMismatchException if {@code this} and {@code directionToPack} are not * expressed in the same reference frame. */ default void getDirection(boolean normalize, FixedFrameVector3DBasics directionToPack) { checkReferenceFrameMatch(directionToPack); LineSegment3DReadOnly.super.getDirection(normalize, directionToPack); }
/** * Tests whether the projection of the given point onto this line segment is located between the two * endpoints or exactly on an endpoint. * * @param point the query. Not modified. * @return {@code true} if the projection of the point is between the endpoints of this line * segment, {@code false} otherwise. */ default boolean isBetweenEndpoints(Point3DReadOnly point) { return isBetweenEndpoints(point, 0); }
/** * Computes the orthogonal projection of a 3D point on this 3D line segment. * <p> * Edge cases: * <ul> * <li>if the length of this line segment is too small, i.e. * {@code this.lengthSquared() < }{@link EuclidGeometryTools#ONE_TRILLIONTH}, this method returns * {@code firstEndpoint}. * <li>the projection can not be outside the line segment. When the projection on the corresponding * line is outside the line segment, the result is the closest of the two endpoints. * </ul> * </p> * * @param pointToProject the point to project on this line segment. Modified. * @return whether the method succeeded or not. */ default boolean orthogonalProjection(Point3DBasics pointToProject) { return orthogonalProjection(pointToProject, pointToProject); }
/** * Computes the coordinates of the point located exactly at the middle of this line segment. * * @param midpointToPack point in which the mid-point of this line segment is stored. Modified. * @throws ReferenceFrameMismatchException if {@code this} and {@code midpointToPack} are not * expressed in the same reference frame. */ default void midpoint(FixedFramePoint3DBasics midpointToPack) { checkReferenceFrameMatch(midpointToPack); LineSegment3DReadOnly.super.midpoint(midpointToPack); }
/** * Computes the coordinates of the point located on the line this line segment is lying on: <br> * {@code pointToPack.interpolate(firstEndpoint, secondEndpoint, percentage)} </br> * * @param percentage the percentage along this line segment of the point. * @param pointToPack where the result is stored. Modified. * @throws ReferenceFrameMismatchException if {@code this} and {@code pointToPack} are not expressed * in the same reference frame. */ default void pointOnLineGivenPercentage(double percentage, FixedFramePoint3DBasics pointToPack) { checkReferenceFrameMatch(pointToPack); LineSegment3DReadOnly.super.pointOnLineGivenPercentage(percentage, pointToPack); }
/** * Computes the coordinates of the point located at a given percentage on this line segment: <br> * {@code pointToPack.interpolate(firstEndpoint, secondEndpoint, percentage)} </br> * * @param percentage the percentage along this line segment of the point. Must be in [0, 1]. * @param pointToPack where the result is stored. Modified. * @throws {@link RuntimeException} if {@code percentage} ∉ [0, 1]. * @throws ReferenceFrameMismatchException if {@code this} and {@code pointToPack} are not expressed * in the same reference frame. */ default void pointBetweenEndpointsGivenPercentage(double percentage, FixedFramePoint3DBasics pointToPack) { checkReferenceFrameMatch(pointToPack); LineSegment3DReadOnly.super.pointBetweenEndpointsGivenPercentage(percentage, pointToPack); }
/** * Tests whether the projection of the given point onto this line segment is located between the two * endpoints with a given conservative tolerance {@code epsilon}: * <ul> * <li>if {@code epsilon > 0}, the point has to be between the endpoints and at a minimum distance * of {@code epsilon * this.length()} from the closest endpoint. * <li>if {@code epsilon < 0}, the point has to be between the endpoints or at a maximum distance of * {@code -epsilon * this.length()} from the closest endpoint. * <li>if {@code epsilon = 0}, the point has to be between the endpoints or equal to one of the * endpoints. * </ul> * * @param x the x-coordinate of the query point. * @param y the y-coordinate of the query point. * @param z the z-coordinate of the query point. * @param epsilon the tolerance to use. * @return {@code true} if the projection of the point is between the endpoints of this line * segment, {@code false} otherwise. */ default boolean isBetweenEndpoints(double x, double y, double z, double epsilon) { double alpha = percentageAlongLineSegment(x, y, z); if (alpha < epsilon) return false; if (alpha > 1.0 - epsilon) return false; return true; }
/** * Tests on a per-component basis on both endpoints if this line segment is equal to {@code other} * with the tolerance {@code epsilon}. * <p> * If the two line segments have different frames, this method returns {@code false}. * </p> * * @param other the query. Not modified. * @param epsilon the tolerance to use. * @return {@code true} if the two line segments are equal and are expressed in the same reference * frame, {@code false} otherwise. */ default boolean epsilonEquals(FrameLineSegment3DReadOnly other, double epsilon) { if (getReferenceFrame() != other.getReferenceFrame()) return false; return LineSegment3DReadOnly.super.epsilonEquals(other, epsilon); }
/** * This methods computes the minimum distance between this line segment and the given one. * <a href="http://geomalgorithms.com/a07-_distance.html"> Useful link</a>. * * @param frameLineSegment3DReadOnly the other line segment to compute the distance from. Not * modified. * @return the minimum distance between the two line segments. * @throws ReferenceFrameMismatchException if {@code this} and {@code frameLineSegment3DReadOnly} * are not expressed in the same reference frame. */ default double distance(FrameLineSegment3DReadOnly frameLineSegment3DReadOnly) { checkReferenceFrameMatch(frameLineSegment3DReadOnly); return LineSegment3DReadOnly.super.distance(frameLineSegment3DReadOnly); }
/** * Computes the orthogonal projection of a 3D point on this 3D line segment. * <p> * Edge cases: * <ul> * <li>if the length of this line segment is too small, i.e. * {@code this.lengthSquared() < }{@link EuclidGeometryTools#ONE_TRILLIONTH}, this method returns * {@code firstEndpoint}. * <li>the projection can not be outside the line segment. When the projection on the corresponding * line is outside the line segment, the result is the closest of the two endpoints. * </ul> * </p> * * @param pointToProject the point to project on this line segment. Modified. * @return whether the method succeeded or not. * @throws ReferenceFrameMismatchException if {@code this} and {@code pointToProject} are not * expressed in the same reference frame. */ default boolean orthogonalProjection(FixedFramePoint3DBasics pointToProject) { checkReferenceFrameMatch(pointToProject); return LineSegment3DReadOnly.super.orthogonalProjection(pointToProject); }
/** * Computes and returns the coordinates of the point located exactly at the middle of this line * segment. * <p> * WARNING: This method generates garbage. * </p> * * @return the mid-point of this line segment. */ default Point3DBasics midpoint() { Point3D midpoint = new Point3D(); midpoint(midpoint); return midpoint; }
/** * Computes the coordinates of the point located on the line this line segment is lying on: <br> * {@code pointToPack.interpolate(firstEndpoint, secondEndpoint, percentage)} </br> * <p> * WARNING: This method generates garbage. * </p> * * @param percentage the percentage along this line segment of the point. * @return the computed point. */ default Point3DBasics pointOnLineGivenPercentage(double percentage) { Point3D point = new Point3D(); pointOnLineGivenPercentage(percentage, point); return point; }
/** * Computes the coordinates of the point located at a given percentage on this line segment: <br> * {@code pointToPack.interpolate(firstEndpoint, secondEndpoint, percentage)} </br> * <p> * WARNING: This method generates garbage. * </p> * * @param percentage the percentage along this line segment of the point. Must be in [0, 1]. * @return the computed point. * @throws {@link RuntimeException} if {@code percentage} ∉ [0, 1]. */ default Point3DBasics pointBetweenEndpointsGivenPercentage(double percentage) { Point3D point = new Point3D(); pointBetweenEndpointsGivenPercentage(percentage, point); return point; }
return LineSegment3DReadOnly.super.percentageAlongLineSegment(point);
/** * Asserts on a per component basis that the two line segment 3Ds are equal to an * {@code epsilon}. * <p> * Note: the two arguments are considered to be equal if they are both equal to {@code null}. * </p> * * @param messagePrefix prefix to add to the error message. * @param expected the expected line segment 3D. Not modified. * @param actual the actual line segment 3D. Not modified. * @param epsilon the tolerance to use. * @param format the format to use for printing each component when an {@code AssertionError} is * thrown. * @throws AssertionError if the two line segment 3Ds are not equal. If only one of the arguments * is equal to {@code null}. */ public static void assertLineSegment3DEquals(String messagePrefix, LineSegment3DReadOnly expected, LineSegment3DReadOnly actual, double epsilon, String format) { if (expected == null && actual == null) return; if (!(expected != null && actual != null)) throwNotEqualAssertionError(messagePrefix, expected, actual, format); if (!expected.epsilonEquals(actual, epsilon)) { throwNotEqualAssertionError(messagePrefix, expected, actual, format); } }
/** * Returns the minimum distance between a point and this given line segment. * <p> * Edge cases: * <ul> * <li>if {@code this.lengthSquared() < }{@link EuclidGeometryTools#ONE_TRILLIONTH}, this method * returns the distance between {@code firstEndpoint} and the given {@code point}. * </ul> * </p> * * @param point 3D point to compute the distance from this line segment. Not modified. * @return the minimum distance between the 3D point and this 3D line segment. * @throws ReferenceFrameMismatchException if {@code this} and {@code point} are not expressed in * the same reference frame. */ default double distance(FramePoint3DReadOnly point) { checkReferenceFrameMatch(point); return LineSegment3DReadOnly.super.distance(point); }
/** * Computes the orthogonal projection of a 3D point on this 3D line segment. * <p> * Edge cases: * <ul> * <li>if the length of this line segment is too small, i.e. * {@code this.lengthSquared() < }{@link EuclidGeometryTools#ONE_TRILLIONTH}, this method returns * {@code firstEndpoint}. * <li>the projection can not be outside the line segment. When the projection on the corresponding * line is outside the line segment, the result is the closest of the two endpoints. * </ul> * </p> * * @param pointToProject the point to compute the projection of. Not modified. * @param projectionToPack point in which the projection of the point onto this line segment is * stored. Modified. * @return whether the method succeeded or not. * @throws ReferenceFrameMismatchException if {@code this} and {@code pointToProject} are not * expressed in the same reference frame. */ default boolean orthogonalProjection(FramePoint3DReadOnly pointToProject, Point3DBasics projectionToPack) { checkReferenceFrameMatch(pointToProject); return LineSegment3DReadOnly.super.orthogonalProjection(pointToProject, projectionToPack); }
/** * Tests whether the projection of the given point onto this line segment is located between the two * endpoints or exactly on an endpoint. * * @param point the query. Not modified. * @return {@code true} if the projection of the point is between the endpoints of this line * segment, {@code false} otherwise. * @throws ReferenceFrameMismatchException if {@code this} and {@code point} are not expressed in * the same reference frame. */ default boolean isBetweenEndpoints(FramePoint3DReadOnly point) { checkReferenceFrameMatch(point); return LineSegment3DReadOnly.super.isBetweenEndpoints(point); }
/** * Computes the coordinates of the point located exactly at the middle of this line segment. * * @param midpointToPack point in which the mid-point of this line segment is stored. Modified. */ @Override default FramePoint3DBasics midpoint() { return new FramePoint3D(getReferenceFrame(), LineSegment3DReadOnly.super.midpoint()); }