MATLAB Answers


How to rotate a line using Matlab?

Asked by Makrim
on 16 May 2015
Latest activity Commented on by Makrim
on 16 May 2015
Suppose I have an image I and a line h1. Using Matlab, I can draw the line (or segment) like this (in red) :
h1 = plot( [l1 l1],[20 100], 'r');
Now I want to rotate the image I with an angle of 45°. So I used imrotate like this:
IR = imrotate(I,45);
Now, I want to rotate the line, how to do that using Matlab ?
PS: I found the function rotate. I am trying this, but it is not working !
rotate(h1,[1 1],45);


Sign in to comment.



1 Answer

Answer by Image Analyst
on 16 May 2015
 Accepted Answer

imrotate() rotates an entire image, not a line you created with line() or plot(). You need to take your points and multiply by the rotation matrix - you know, the sin and cos thing you learned in your linear algebra class in college. Then call line() or plot() again with the rotated coordinates.

  1 Comment

it worked for the two points of the line ... thank you

Sign in to comment.