Saturday, February 11, 2006

playing with ellipse

i was trying to plot an ellipse on matlab figure window for one class homework and that problem turned out to be an interesting one..
first i started off with a basic ellipse equation and it involved little challenge.. the main task came when i was supposed to plot a tilted ellipse.. here is the code.. try it and have fun...

---------------------------------------------------------------------------------------
function [xout,yout1,yout2] = my_ellipse(x1,y1,a,b,c,rot)
%
%function [xout,yout1,yout2] = my_ellipse(x1,y1,a,b,c,rot)
%this one draws a ellipse.
%
% Input values:
% Centre = (x1,y1)
% semimajor axis = a
% semiminor axis = b
%
% 2
% covariance XY = c
%
% rot: 1 for clockwise roatition
% -1 for anti clockwise rotation.
%
% Equation of the ellipse is written as
% 2 2
% (x-x1) (y-y1) (x-x1)(y-y1)
% ------ + ----- - ------------ = 1
% 2 2 2
% a b c
%
%
%
% which uses
% 2 2
% p(X) + q(Y) - r(XY) - s = 0;
% where X = x-x1
% Y = y-y1
%
% plot : use the following
% plot(xout,yout1);hold on; plot(xout,yout2);


s = 1;
p = s/a^2;
q = s/b^2;
if nargin <6 rot =" 1;" r =" 0;" r =" rot*s/c^2;" lim =" sqrt(s/abs(p" x =" [-lim:2*lim/100:lim];" y =" b*sqrt(1" y1 =" (r*X" y2 =" (r*X" xout =" X+x1;" yout1 =" Y1+y1;" yout2 =" Y2+y1;" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://photos1.blogger.com/blogger/648/1137/1600/1.0.jpg">

0 Comments:

Post a Comment

<< Home