5.4 How to draw an ellipse?

5.4.1 draw an ellipse centered at origin and given its semi-major/minor \((a,b)\)
5.4.2 draw an ellipse centered at \((x,y\)) and given its semi-major/minor \((a,b)\)
5.4.3 draw an ellipse centered at origin and given its semi-major/minor \((a,b)\) and rotated at angle \(\theta \)

5.4.1 draw an ellipse centered at origin and given its semi-major/minor \((a,b)\)

draw an ellipse centered at \((0,0)\) with \(a=2,b=1\) being its semi-major and minor.

The ellipse equation for the above is \(\frac {x^2}{a^2}+\frac {y^2}{b^2}=1\)

Mathematica

a = 2; 
b = 1; 
Graphics[Circle[{0, 0}, {a, b}], Axes -> True]
 

pict

 

Matlab

a=2; 
b=1; 
t=linspace(0,2*pi,50); 
plot(a*cos(t),b*sin(t)) 
axis equal
 

pict

 

5.4.2 draw an ellipse centered at \((x,y\)) and given its semi-major/minor \((a,b)\)

draw an ellipse centered at \((1,2)\) with \(a=2,b=1\) being its semi-major and minor. The ellipse equation for the above is \(\frac {x^2}{a^2}+\frac {y^2}{b^2}=1\)

Mathematica

a = 2; 
b = 1; 
Graphics[ 
 { 
  Circle[{1, 2}, {a, b}], 
  Point[{1, 2}] 
  }, Axes -> True 
 ]
 

pict

 

Matlab

close all; 
a=2; b=1; 
t=linspace(0,2*pi,50); 
plot(a*cos(t)+1,b*sin(t)+2) 
axis equal 
xlim([-1,4]); 
ylim([0,4]);
 

pict

 

5.4.3 draw an ellipse centered at origin and given its semi-major/minor \((a,b)\) and rotated at angle \(\theta \)

draw an ellipse centered at \((0,0)\) with \(a=2,b=1\) being its semi-major and minor titlted at angle \(\theta =30\,\text {degrees}\) anti-clockwise.

The ellipse equation for the above is \(\frac {x^2}{a^2}+\frac {y^2}{b^2}=1\). After drawing it, we rotate it.

Mathematica

a = 2; 
b = 1; 
Graphics[ 
 Rotate[ 
  {Circle[{0, 0}, {a, b}], 
   Line[{{-a, 0}, {a, 0}}], 
   Line[{{0, -b}, {0, b}}] 
   } 
  , 30 Degree 
  ] 
 , Axes -> True 
 ]
 

pict

 

Matlab

Matlab does not have rotate function, so use the rotation tranformation matrix.

close all; 
a   = 2; 
b   = 1; 
t   = linspace(0,2*pi,50); 
rotateAngle = 30*pi/180; 
mat = [cos(rotateAngle) -sin(rotateAngle) 
       sin(rotateAngle) cos(rotateAngle)]; 
 
%2x2 times 2x50 = 2x50 
data = mat*[a*cos(t);b*sin(t)]; 
plot(data(1,:),data(2,:)) 
axis equal
 

pict