I'm drawing a graph with two points of each point having a line with a weight.
for example graph: point "15" to point "16" line with the weight of 1.872 and point "16" to point "15" with the weight of 1.567.
take a look at my graph for now:
I want to draw a String with always parallel (adjacent) to the line.
I calculated the slope for the straight and the angel I did calculate is the arctan of this slope:
I had use this function to rotate the string:
public static void drawRotate(Graphics2D g2d, double x, double y, double angle, String text) {
g2d.translate((float)x,(float)y);
g2d.rotate(Math.toRadians(angle));
g2d.drawString(text,0,0);
g2d.rotate(-Math.toRadians(angle));
g2d.translate(-(float)x,-(float)y);
}
With the angle of arctan((y2-y1)/(x2-x1)= the slope of the line ) and it didn't work well.
How can I rotate this String to run parallel always to the line I draw?
My goal: Draw the String like this example


