Line2d implements Path2d, Cloneable { public double calculateHorizontalAngle() { return Math.atan((end.getY() - begin.getY()) / (end.getX() - begin.getX())); } 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 testAngle() { Line2d line1 = new Line2d( new Point2dImpl(0,0), new Point2dImpl(4,4) ); Line2d line2 = new Line2d( new Point2dImpl(0,0), new Point2dImpl(4,0) ); Line2d line3 = new Line2d( new Point2dImpl(0,0), new Point2dImpl(0,4) ); assertEquals( 45, line1.calculateHorizontalAngle()*RAD2DEG, 1d ); assertEquals( 0, line2.calculateHorizontalAngle()*RAD2DEG, 1d ); assertEquals( 90, line3.calculateHorizontalAngle()*RAD2DEG, 1d ); }