/** * Translates this line segment by the given (x, y, z) contained in {@code translation}. * <p> * Note that the length and direction of this line segment remains unchanged. * </p> * * @param translation the translation to add to each endpoint of this line segment. Not modified. * @throws ReferenceFrameMismatchException if {@code this} and {@code translation} are not expressed * in the same reference frame. */ default void translate(FrameTuple2DReadOnly translation) { checkReferenceFrameMatch(translation); LineSegment2DBasics.super.translate(translation); } }
/** * Translates this line segment by the given (x, y) contained in {@code translation}. * <p> * Note that the length and direction of this line segment remains unchanged. * </p> * * @param translation the translation to add to each endpoint of this line segment. Not modified. */ default void translate(Tuple2DReadOnly translation) { translate(translation.getX(), translation.getY()); }
/** * Translates this line segment perpendicularly to its direction. * * @param shiftToLeft defines to which side this line segment is to be translated. * @param distanceToShift the distance this line segment is to be shifted. */ default void shift(boolean shiftToLeft, double distanceToShift) { double vectorX = getSecondEndpointX() - getFirstEndpointX(); double vectorY = getSecondEndpointY() - getFirstEndpointY(); double length = length(); double orthogonalVectorX = -vectorY / length; double orthogonalVectorY = vectorX / length; if (!shiftToLeft) { orthogonalVectorX = -orthogonalVectorX; orthogonalVectorY = -orthogonalVectorY; } orthogonalVectorX = distanceToShift * orthogonalVectorX; orthogonalVectorY = distanceToShift * orthogonalVectorY; translate(orthogonalVectorX, orthogonalVectorY); }