How to find the angle of a line with respect to plot window
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
himura
am 23 Mär. 2023
Bearbeitet: himura
am 23 Mär. 2023
This is a little hard to explain. I am not looking for the angle of the line with respect to the cartesian coordinates, I am looking for the angle with respect to the plot window itself.
For context, I am trying to use this angle to produce some text that has the same angle as the line
For Example:
plot([0:10], [0:10])
text( 0, 0, "----------------------some text", Rotation = 45)
p = subplot(1,1,1);
disp(p.Position(3:4))
See how the text angle doesn't match the line angle, and the plot itself is not a square
i- I'd imagine some calculations are in order, and it would need the size of the window as an input.
ii- I also thought that ths cannot be that complex, surely there's a way to write text on the plot at an angle relative to the plot's coordiates, right?
If anyone has someinsight on (i) or (ii), that would be highly appriociated!
0 Kommentare
Akzeptierte Antwort
Joe Vinciguerra
am 23 Mär. 2023
plot([0:10], [0:10])
ar = get(gca, "PlotBoxAspectRatio")
r = atand(ar(2)/ar(1)) % This will give you the angle of the diagonal of the axes in degrees
text( 0, 0, "----------------------some text", Rotation = r)
Then compare it to the slope of the line you are plotting.
1 Kommentar
Siehe auch
Kategorien
Mehr zu Annotations finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!