Plotting an Ellipse

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 http://www.mathworks.com/help/toolbox/mupad/plot/PRIMITIV_Ellipse2d.html, 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 Commento

Walter Roberson
Walter Roberson il 15 Giu 2012
Could you show us a sample of how you are invoking that routine?

Accedi per commentare.

Risposte (1)

David Legland
David Legland il 4 Lug 2012
Modificato: David Legland il 4 Lug 2012
Hi,
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 Commento

Minor typo in the rotation:
replace
y = xt * sit - yt * cot;
with
y = xt * sit + yt * cot;

Accedi per commentare.

Categorie

Scopri di più su Loops and Conditional Statements in Centro assistenza e File Exchange

Richiesto:

il 15 Giu 2012

Commentato:

il 16 Gen 2020

Community Treasure Hunt

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

Start Hunting!

Translated by