Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Ellipe drawing

Subject: Ellipe drawing

From: aalcaineo

Date: 21 Jun, 2013 10:16:09

Message: 1 of 3

Hello all

I'm trying to draw an ellipse in the same fashion I did it for a circle, I let you an example

[X,Y] = meshgrid(0:1/SpatSamp:Xmax,0:1/SpatSamp:Ymax);
Act = sqrt((X-Loc(1)).^2+(Y-Loc(2)).^2);

where SpatSamp is the spatial sampling, Xmax and Ymax are the limits y Loc is a vector with the X,Y coordinates of the center.

the objective is to plot it using "contour"

Any ideas? thank you in advance for your help!

Subject: Ellipe drawing

From: TideMan

Date: 21 Jun, 2013 21:35:02

Message: 2 of 3

On Friday, June 21, 2013 10:16:09 PM UTC+12, aalcaineo wrote:
> Hello all
>
>
>
> I'm trying to draw an ellipse in the same fashion I did it for a circle, I let you an example
>
>
>
> [X,Y] = meshgrid(0:1/SpatSamp:Xmax,0:1/SpatSamp:Ymax);
>
> Act = sqrt((X-Loc(1)).^2+(Y-Loc(2)).^2);
>
>
>
> where SpatSamp is the spatial sampling, Xmax and Ymax are the limits y Loc is a vector with the X,Y coordinates of the center.
>
>
>
> the objective is to plot it using "contour"
>
>
>
> Any ideas? thank you in advance for your help!

That's a weird way of plotting an ellipse.

Here's an alternative for an ellipse with major axis qmax and minor axis qmin, centre at x0,y0, and orientated theta deg from N.
function [x,y]=ellipse(qmax,qmin,theta,x0,y0,n)
%
% Set up parameters
%
theta=theta*pi/180; % Orientation from N
wt=0:n; % n is no of points 180 is good
dwt=2*pi/n;
wt=wt'*dwt;
sth=sin(theta);
cth=cos(theta);
%
% Calculate ellipse with zero orientation
%
x1=qmax*cos(wt);
y1=qmin*sin(wt);
%
% Orientate theta deg from north
%
x=x1*sth-y1*cth+x0;
y=x1*cth+y1*sth+y0;

plot(x,y)

Subject: Ellipe drawing

From: Nasser M. Abbasi

Date: 21 Jun, 2013 22:06:50

Message: 3 of 3

On 6/21/2013 4:35 PM, TideMan wrote:

>
> Here's an alternative for an ellipse with major axis qmax and minor axis qmin, centre at x0,y0, and orientated theta deg from N.
> function [x,y]=ellipse(qmax,qmin,theta,x0,y0,n)
> %
> % Set up parameters
> %
> theta=theta*pi/180; % Orientation from N
> wt=0:n; % n is no of points 180 is good
> dwt=2*pi/n;
> wt=wt'*dwt;
> sth=sin(theta);
> cth=cos(theta);
> %
> % Calculate ellipse with zero orientation
> %
> x1=qmax*cos(wt);
> y1=qmin*sin(wt);
> %
> % Orientate theta deg from north
> %
> x=x1*sth-y1*cth+x0;
> y=x1*cth+y1*sth+y0;
>
> plot(x,y)
>

And if one is adventurous and want to do the plotting in Latex, see

http://www.texample.net/tikz/examples/node-shapes/

for many examples

--Nasser

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us