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 θ

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 x2a2+y2b2=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 x2a2+y2b2=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 θ

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

The ellipse equation for the above is x2a2+y2b2=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