Plotting an Ellipse

110 views (last 30 days)
Oliver on 15 Jun 2012
Commented: Nshine on 16 Jan 2020
I'm trying to draw a 2D ellipse. I know that I can use the rectangle function and set the curvature equal to 1, but I came across this page, and I was wondering how I would implement it. It looks like it could be very useful, but whenever I try it says it cannot recognize the char inputs.
  1 Comment
Walter Roberson
Walter Roberson on 15 Jun 2012
Could you show us a sample of how you are invoking that routine?

Sign in to comment.

Answers (1)

David Legland
David Legland on 4 Jul 2012
Edited: David Legland on 4 Jul 2012
Maybe the best way to draw an ellipse is to use its parametric form:
% compute points corresponding to axis-oriented ellipse
t = linspace(0, 2*pi, 200);
xt = r1 * cos(t) + xc;
yt = r2 * sin(t) + yc;
% aply rotation by angle theta
cot = cos(theta); sit = sin(theta);
x = xt * cot - yt * sit;
y = xt * sit - yt * cot;
% draw the curbe
plot(x, y, '-');
This can be easily converted to a single function.
  1 Comment
Nshine on 16 Jan 2020
Minor typo in the rotation:
y = xt * sit - yt * cot;
y = xt * sit + yt * cot;

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!