橢圓

要繪製橢圓,你可以使用其等式 。橢圓具有長軸和短軸。此外,我們希望能夠在不同的中心點上繪製橢圓。因此我們編寫一個函式,其輸入和輸出是:

Inputs:
    r1,r2: major and minor axis respectively
    C: center of the ellipse (cx,cy)
Output:
    [x,y]: points on the circumference of the ellipse

你可以使用以下函式獲取橢圓上的點,然後繪製這些點。

function [x,y] = getEllipse(r1,r2,C)
beta = linspace(0,2*pi,100);
x = r1*cos(beta) - r2*sin(beta);
y = r1*cos(beta) + r2*sin(beta);
x = x + C(1,1);
y = y + C(1,2);
end

〔實施例:

[x,y] = getEllipse(1,0.3,[2 3]);
plot(x,y);

StackOverflow 文件