Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com 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

Status
Not open for further replies.

ayham87

Newbie level 6
Joined
Oct 4, 2008
Messages
12
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,349
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

Code:
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:

xr=xe•cos(φ)-ye•sin(φ)
yr=xe•sin(φ)+ye•cos(φ)

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;

R=xRadius;
isoview(-20,20,-20,20);

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

phi=0*%pi/180;

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

plot(xr, yr, 'r');


phi=120*%pi/180;

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

plot(xr, yr, 'b');


phi=240*%pi/180;

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:

X_shift=5;
Y_shift=8;
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.

Code:
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
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top