Line2d implements Path2d, Cloneable { public Point2d reflectAroundLine(Point2d pointToReflect) { double nx = end.getX() - begin.getX(); double ny = end.getY() - begin.getY(); final double d = Math.sqrt(nx * nx + ny * ny); nx /= d; ny /= d; final double px = pointToReflect.getX() - begin.getX(); final double py = pointToReflect.getY() - begin.getY(); final double w = nx * px + ny * py; final double rx = 2 * begin.getX() - pointToReflect.getX() + 2 * w * nx; final double ry = 2 * begin.getY() - pointToReflect.getY() + 2 * w * ny; return new Point2dImpl((float) rx, (float) ry); } Line2d();  Line2d(Point2d begin, Point2d end);  Line2d(float x1, float y1, float x2, float y2); void setBeginPoint(Point2d begin); void setEndPoint(Point2d end); Point2d getBeginPoint(); Point2d getEndPoint(); Point2d setEndPoint(); IntersectionResult getIntersection(Line2d otherLine); Point2d reflectAroundLine(Point2d pointToReflect); Line2d lineWithinSquare(Rectangle r); static double distance(Point2d p1, Point2d p2); static double distance(float p1x, float p1y, float p2x, float p2y); static Line2d lineFromRotation(int x1, int y1, double theta, int length); @Override double calculateLength(); double calculateHorizontalAngle(); double calculateVerticalAngle(); @Override Line2d transform(Matrix transform); Line2d getNormal(); Line2d getNormal(Point2d p); @Override void translate(float x, float y); boolean isInLine(Point2d p, float tolerance); @Override String toString(); @Override Rectangle calculateRegularBoundingBox(); @Override void scale(float sc); @Override void scale(Point2d centre, float sc); @Override void scaleCentroid(float sc); @Override Point2d calculateCentroid(); @Override double minX(); @Override double minY(); @Override double maxX(); @Override double maxY(); @Override double getWidth(); @Override double getHeight(); Point2dImpl toUnitVector(); @Override Line2d clone(); @Override int hashCode(); @Override boolean equals(Object other); @Override Point2d begin(); @Override Point2d end(); @Override Polyline asPolyline(); @Override Iterator<Line2d> lineIterator(); boolean isOnLine(Point2d p, float tolerance); float distanceToLine(Point2d p); public Point2d begin; public Point2d end; }
@Test public void testReflection() { Line2d line = new Line2d( new Point2dImpl(0,0), new Point2dImpl(8,4) ); Point2d reflection = line.reflectAroundLine( new Point2dImpl( 1,2 ) ); assertEquals(2.2, reflection.getX(), 0.001); assertEquals(-0.4, reflection.getY(), 0.001); }