MATLAB Answers

how can I rotate the ellipses based on the orientation angle of (x_i,y_i)?

51 views (last 30 days)
Noob
Noob on 16 Jun 2017
Answered: Giulio Antufermo on 14 Jan 2020
I would like to rotate the ellipses to show the orientation, theta, of the centered data points.

  0 Comments

Sign in to comment.

Accepted Answer

KSSV
KSSV on 16 Jun 2017
a=5; % horizontal radius
b=10; % vertical radius
x0=0; % x0,y0 ellipse centre coordinates
y0=0;
t=-pi:0.01:pi;
x=x0+a*cos(t);
y=y0+b*sin(t);
plot(x,y)
hold on
%%Rotate the ellipse by 90 degrees
th = pi/2 ;
R = [cos(th) -sin(th) ; sin(th) cos(th)] ;
% Rotate all the points
P = zeros(2,length(x)) ;
for i =1:length(x)
P(:,i) = R*[x(i) ;y(i)] ;
end
xr = P(1,:) ; yr = P(2,:) ;
plot(xr,yr,'r')

  3 Comments

KSSV
KSSV on 16 Jun 2017
You have not given any data here...Provided you know the angle of theta by which you want to rotate ellipse....this is the way to rotate. Your question was this only, how to rotate ellipse.
KSSV
KSSV on 16 Jun 2017
YOu have to run it in a loop....
for i = 1:length(x_i) ;
P(:,i) = R * [x_i(i) ; y_i(i)];
end

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!