Continue to Site

Welcome to

Welcome to our site! is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] ellipsis draw by matlab

Not open for further replies.


Newbie level 6
Oct 4, 2008
Reaction score
Trophy points
Activity points
Dear friends,

I am trying to draw three ellipsis separated by 120 degree as in the below picture by matlab in the same graph
but i stuck how to complete my code, i started with one ellipse as below

please help

ellipse draws.png

xCenter = 12.5;
yCenter = 10;
xRadius = 2.5;
yRadius = 8;
theta = 0 : 0.01 : 2*pi;

x = xRadius * cos(theta) + xCenter;
y = yRadius * sin(theta) + yCenter;
plot(x, y, 'LineWidth', 3);
axis square;
xlim([0 20]);
ylim([0 20]);
grid on;

In order to generate an ellipse orientated along an axis that forms an angle φ with respect to the abscissa you have to apply the rotation of coordinates to the equation of the ellipse itself.
The equation of the ellipse is (as correctly implemented in you code):

xe=R•cos(θ) + xCenter
ye=R•sin(θ) + yCenter

the rotation is given by:


In order to have three ellipses 120° spaced, simply apply φ1=0°, φ2=120°, φ3=240°.

Since the axis rotation will rotate (of course) also the center, if xCenter=0 and yCenter=0 the centers af the three ellipses will be the same and equal to (0,0), so to have also a rotation of the center you will need to place it at a certain distance from the origin. To have the ellispses touching in a single point simply set to 0 the center corresponding to the minor axis of the ellipse and set the other at the same value of the radius of the major axis.

If, for instance: xRadius=8, yRadius=3, then xCenter=8, yCenter=0
and if xRadius=4, yRadius=7, then xCenter=0, yCenter=7

I wrote a code for Scilab. It is very similar to Matlab then with minor changes you can run it of that platform (for instance "isoview" stays for "axis square" and "%pi" stays for "pi").

xCenter = 0;
yCenter = 8;
xRadius = 2;
yRadius = 8;
theta = 0 : 0.01 : 2*%pi;


x = xRadius * cos(theta)+xCenter;
y = yRadius * sin(theta)+yCenter;


xr = x*cos(phi)-y*sin(phi);
yr = x*sin(phi)+y*cos(phi);

plot(xr, yr, 'r');


xr = x*cos(phi)-y*sin(phi);
yr = x*sin(phi)+y*cos(phi);

plot(xr, yr, 'b');


xr = x*cos(phi)-y*sin(phi);
yr = x*sin(phi)+y*cos(phi);

plot(xr, yr, 'g');

If you need the ellipses to be intersecated, simply decrease the value of yCenter.
Thanks Albbg

I simulated the code but i got the below error, please help:

??? Error using ==> axis at 183
Unknown command option square(-20,20,-20,20)

I think because you cannot directly translate isoview(-20,20,-20,20) into axis square(-20,20,-20,20).
I'm not sure about Matlab synopsis, but it seems you have to use a similar code to your, that is:

axis square
xlim([-20 20]);
ylim([-20 20]);
grid on;
Thanks a lot Albbg

It works with me now

last thing, i tried to shift the ellipsis plot coordinates out of (0,0) to another coordinate but i couldn't . could you tell me how can i plot on any specific coordinate?

Thanks again in advanced

I shifted the ellipsis by defining shifts for the plot as:

plot(xr+X_shift, yr+X_shift, 'r');

It's correct, then you solved the problem.

Perhaps it's a little bit short using complex numbers.

xRadius = 2.5;
yRadius = 8;
theta = [0 : 0.01 : 2*pi]';

yshift = 6 ; % sqrt(yRadius^2-xRadius^2) if confocals ellipses

z = xRadius*cos(theta) + i*(yRadius*sin(theta)+yshift);
R120 = cos(2*pi/3) + i*sin(2*pi/3);

plot(z*[1,R120,R120'], 'LineWidth', 3);
axis square;
xlim([-15 15]);
ylim([-15 15]);
grid on;

Thanks a lot

Do you know how can i insert numbering for the ellipses as below figure

i need only how to add the values inside each ellipse

ellipse draws.png

Not open for further replies.

Part and Inventory Search

Welcome to