/** * Applies a counter-clockwise rotation to the direction of this line about the z-axis by * {@code angleInRadians}. * <p> * Note that the point of this line remains unchanged. * </p> * * @param angleInRadians the angle to rotate this line's direction in radians. */ default void rotate(double angleInRadians) { RotationMatrixTools.applyYawRotation(angleInRadians, getDirection(), getDirection()); }
/** * Sets this line to be the same as the given line. * * @param other the other line to copy. Not modified. */ @Override public void set(Line2D other) { Line2DBasics.super.set(other); }
/** * Redefines this line with a new point and a new direction vector. * * @param pointOnLine new point on this line. Not modified. * @param lineDirection new direction of this line. Not modified. */ default void set(Point3DReadOnly pointOnLine, Vector3DReadOnly lineDirection) { setPoint(pointOnLine); setDirection(lineDirection); }
/** * Translates this line perpendicularly to its direction. * * @param shiftToLeft defines to which side this line is to be translated. * @param distanceToShift the distance this line is to be shifted. */ default void shift(boolean shiftToLeft, double distanceToShift) { double vectorX = getDirectionX(); double vectorY = getDirectionY(); double orthogonalVectorX = -vectorY; double orthogonalVectorY = vectorX; if (!shiftToLeft) { orthogonalVectorX = -orthogonalVectorX; orthogonalVectorY = -orthogonalVectorY; } orthogonalVectorX = distanceToShift * orthogonalVectorX; orthogonalVectorY = distanceToShift * orthogonalVectorY; translate(orthogonalVectorX, orthogonalVectorY); }
/** * Tests if this line contains {@link Double#NaN}. * * @return {@code true} if {@link #getPoint()} and/or {@link #getDirection()} contains {@link Double#NaN}, * {@code false} otherwise. */ @Override default boolean containsNaN() { return getPoint().containsNaN() || getDirection().containsNaN(); }
/** * Redefines this line such that it goes through the two given points. * * @param firstPointOnLine first point on this line. Not modified. * @param secondPointOnLine second point on this line. Not modified. */ default void set(Point2DReadOnly firstPointOnLine, Point2DReadOnly secondPointOnLine) { // checkDistinctPoints if (firstPointOnLine.equals(secondPointOnLine)) { throw new RuntimeException("Tried to create a line from two coincidal points."); } setPoint(firstPointOnLine); getDirection().sub(secondPointOnLine, firstPointOnLine); getDirection().normalize(); }
/** * Changes the point through which this line has to go. * * @param pointOnLine new point on this line. Not modified. */ default void setPoint(Point3DReadOnly pointOnLine) { getPoint().set(pointOnLine); }
@Test public void testPerpendicularLineThroughPoint() { double delta = 1.0e-5; Random random = new Random(8888L); for (int i = 0; i < ITERATIONS; i++) { Point2D firstPointOnLine = randomPoint(random); Point2D secondPointOnLine = randomPoint(random); Line2D line2d = new Line2D(firstPointOnLine, secondPointOnLine); Point2D pointOnPerpendicularLine = randomPoint(random); Line2DBasics perpendicularLine = line2d.perpendicularLineThroughPoint(pointOnPerpendicularLine); assertTrue(perpendicularLine.isPointOnLine(pointOnPerpendicularLine, delta)); assertEquals(0.0, perpendicularLine.getDirection().getX() * line2d.getDirection().getX() + perpendicularLine.getDirection().getY() * line2d.getDirection().getY(), delta); } }
/** * Changes the point through which this line has to go. * * @param pointOnLine new point on this line. Not modified. * @throws ReferenceFrameMismatchException if {@code this} and {@code pointOnLine} are not * expressed in the same reference frame. */ default void setPoint(FramePoint2DReadOnly pointOnLine) { checkReferenceFrameMatch(pointOnLine); Line2DBasics.super.setPoint(pointOnLine); }
/** * Changes the direction of this line by setting it to the normalized value of the given vector. * * @param lineDirection new direction of this line. Not modified. * @throws ReferenceFrameMismatchException if {@code this} and {@code lineDirection} are not * expressed in the same reference frame. */ default void setDirection(FrameVector2DReadOnly lineDirection) { checkReferenceFrameMatch(lineDirection); Line2DBasics.super.setDirection(lineDirection); }
/** * Transforms this line using the inverse of the given homogeneous transformation matrix. * * @param transform the transform to apply on this line's point and vector. Not modified. * @throws NotAMatrix2DException if the rotation part of {@code transform} is not a transformation * in the XY-plane. */ @Override default void applyInverseTransform(Transform transform) { applyInverseTransform(transform, true); }
/** * Transforms this line using the given homogeneous transformation matrix. * * @param transform the transform to apply on this line's point and vector. Not modified. * @throws NotAMatrix2DException if the rotation part of {@code transform} is not a transformation * in the XY-plane. */ @Override default void applyTransform(Transform transform) { applyTransform(transform, true); }
/** * Tests on a per-component basis on the point and vector if this line is equal to {@code other} * with the tolerance {@code epsilon}. This method will return {@code false} if the two lines are * physically the same but either the point or vector of each line is different. For instance, if * {@code this.point == other.point} and {@code this.direction == - other.direction}, the two lines * are physically the same but this method returns {@code false}. * * @param other the query. Not modified. * @param epsilon the tolerance to use. * @return {@code true} if the two lines are equal, {@code false} otherwise. */ @Override public boolean epsilonEquals(Line2D other, double epsilon) { return Line2DBasics.super.epsilonEquals(other, epsilon); }
/** * 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. */ @Override public boolean geometricallyEquals(Line2D other, double epsilon) { return Line2DBasics.super.geometricallyEquals(other, epsilon); }
/** * Sets the point and vector of this line to {@link Double#NaN}. After calling this method, this * line becomes invalid. A new valid point and valid vector will have to be set so this line is * again usable. */ @Override default void setToNaN() { getPoint().setToNaN(); getDirection().setToNaN(); }
/** * Redefines this line such that it goes through the two given points. * * @param firstPointOnLine first point on this line. Not modified. * @param secondPointOnLine second point on this line. Not modified. */ default void set(Point3DReadOnly firstPointOnLine, Point3DReadOnly secondPointOnLine) { // checkDistinctPoints if (firstPointOnLine.equals(secondPointOnLine)) { throw new RuntimeException("Tried to create a line from two coincidal points."); } setPoint(firstPointOnLine); getDirection().set(secondPointOnLine); getDirection().sub(firstPointOnLine.getX(), firstPointOnLine.getY()); getDirection().normalize(); }
/** * Changes the point through which this line has to go. * * @param pointOnLine new point on this line. Not modified. */ default void setPoint(Point2DReadOnly pointOnLine) { getPoint().set(pointOnLine); }
/** * Changes the point through which this line has to go. * * @param pointOnLine new point on this line. Not modified. * @throws ReferenceFrameMismatchException if {@code this} and {@code pointOnLine} are not * expressed in the same reference frame. */ default void setPoint(FramePoint3DReadOnly pointOnLine) { checkReferenceFrameMatch(pointOnLine); Line2DBasics.super.setPoint(pointOnLine); }
/** * Changes the direction of this line by setting it to the normalized value of the given vector. * * @param lineDirection new direction of this line. Not modified. * @throws ReferenceFrameMismatchException if {@code this} and {@code lineDirection} are not * expressed in the same reference frame. */ default void setDirection(FrameVector3DReadOnly lineDirection) { checkReferenceFrameMatch(lineDirection); Line2DBasics.super.setDirection(lineDirection); }
/** * Sets the point and vector of this line to zero. After calling this method, this line becomes * invalid. A new valid point and valid vector will have to be set so this line is again usable. */ @Override default void setToZero() { getPoint().setToZero(); getDirection().setToZero(); }