Is this code correct for the ellipse equation given below..?? Will I get rotated ellipse from this code..??

My equation is
I have used Parametric equations of an ellipse here. I need rotated ellipse from this code. But I am getting bent ellipse. Kindly check and let me know the solution asap. *.Mat file is also attached.
th = 0:pi/50:2*pi;
m1=9;
m2=9;
sd1=3;
sd2=2;
r=0.7;
x1 = m1+ (sqrt(1-r^2)*sd1).* cos(th);
x2 = m2+ (sqrt(1-r^2)*sd2).* sin(th);
knum = (2*r*((sqrt(1-r^2)*sd1).* cos(th))* (sqrt(1-r^2)*sd2).* sin(th));
kdenom = (sd1*sd2*(1-r^2));
k=-(knum/kdenom);
h = plot3(x1,x2,k, 'black','linewidth',0.3);
Bent ellipse is like this...
Kindly correct my code to get rotated ellipse properly.

 Accepted Answer

Your attempt to parameterize is invalid, Santhosh. If you do a plot of your original expression, you will see it does not have a constant value.
Here is a parametrization that will produce your ellipse:
t = linspace(0,2*pi);
x1 = m1 + s1*(sqrt(1+r)*cos(t)+sqrt(1-r)*sin(t))/sqrt(2);
x2 = m2 + s2*(sqrt(1+r)*cos(t)-sqrt(1-r)*sin(t))/sqrt(2);
plot(x1,x2)
axis equal
If you use this to evaluate the original expression above, you will see that it is a constant 1 as t varies, (which is the value I assume you wish to set the expression to.)

1 Comment

@ Roger Stafford: It's worked.. I thank you very very much for providing me the code.. Very helpful.. :) :)

Sign in to comment.

More Answers (0)

Categories

Find more on Interactions, Camera Views, and Lighting in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!