Plotting an Ellipse

조회 수: 17 (최근 30일)
Oliver
Oliver 2012년 6월 15일
댓글: Nshine 2020년 1월 16일
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
Walter Roberson
Walter Roberson 2012년 6월 15일
Could you show us a sample of how you are invoking that routine?

댓글을 달려면 로그인하십시오.

답변 (1개)

David Legland
David Legland 2012년 7월 4일
편집: David Legland 2012년 7월 4일
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
Nshine
Nshine 2020년 1월 16일
Minor typo in the rotation:
replace
y = xt * sit - yt * cot;
with
y = xt * sit + yt * cot;

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by