How to draw an ellipse using Octave

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

How to draw an ellipse using Octave

Alphonce Owayo
Hi,

I've been trying to draw an ellipse using Octave I looked for some help online, but all this could do is to draw the equal axis and no ellipse. I am new to Octave however I think its much simpler and user friendly compared to say  Matlab. I believe may be there is some error in the coding. Also how would I change in case I don't want equal axes. I use 4.4.1 (GUI).

 # Draw an ellipse centered in [50 50], with semi major axis length of
  # 40, semi minor axis length of 20, and rotated by 30 degrees.
    figure(1); clf; hold on;
    drawEllipse([0.3 0.2 0.4 0.3 28]);
    axis equal;
Thanks


Reply | Threaded
Open this post in threaded view
|

Re: How to draw an ellipse using Octave

karl
Am 16.01.19 um 05:28 schrieb Alphonce Owayo:
figure(1); clf; hold on;
    drawEllipse([0.3 0.2 0.4 0.3 28]);
    axis equal;

Hi Alphonce,

drawEllipse is part of the package geometry. You have to  install it and load it if you want to use it.

If it is installed, this works:

	load pkg geometry;
	figure(1); clf; hold on;
    	drawEllipse([0.3 0.2 0.4 0.3 28]);
    	axis equal;
  Read the documentation about installing and loading packages! 

Ciao
Karl


Reply | Threaded
Open this post in threaded view
|

Re: How to draw an ellipse using Octave

Doug Stewart-4
In reply to this post by Alphonce Owayo


On Wed, Jan 16, 2019 at 8:55 AM Alphonce Owayo <[hidden email]> wrote:
Hi,

I've been trying to draw an ellipse using Octave I looked for some help online, but all this could do is to draw the equal axis and no ellipse. I am new to Octave however I think its much simpler and user friendly compared to say  Matlab. I believe may be there is some error in the coding. Also how would I change in case I don't want equal axes. I use 4.4.1 (GUI).

 # Draw an ellipse centered in [50 50], with semi major axis length of
  # 40, semi minor axis length of 20, and rotated by 30 degrees.
    figure(1); clf; hold on;
    drawEllipse([0.3 0.2 0.4 0.3 28]);
    axis equal;
Thanks


Your code works for me

--
DASCertificate for 206392



Reply | Threaded
Open this post in threaded view
|

Re: How to draw an ellipse using Octave

karl
In reply to this post by karl
Am 16.01.19 um 15:48 schrieb [hidden email]:
Am 16.01.19 um 05:28 schrieb Alphonce Owayo:
figure(1); clf; hold on;
    drawEllipse([0.3 0.2 0.4 0.3 28]);
    axis equal;

Hi Alphonce,

drawEllipse is part of the package geometry. You have to  install it and load it if you want to use it.

If it is installed, this works:

	load pkg geometry;
	figure(1); clf; hold on;
    	drawEllipse([0.3 0.2 0.4 0.3 28]);
    	axis equal;
  Read the documentation about installing and loading packages! 

Ciao
Karl


    

Error:

It is:

pkg load geometry



Reply | Threaded
Open this post in threaded view
|

Re: How to draw an ellipse using Octave

Pantxo
Or you can draw the ellipse yourself, which is not much longer:

rx = 10; ry = 2;

dx = linspace (0, rx, 100);
dy = ry*sqrt (1-(dx./rx).^2);

x = [dx fliplr(dx) -dx -fliplr(dx)];
y = [dy -fliplr(dy) -dy fliplr(dy)];
plot (x, y)

Pantxo




--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


Reply | Threaded
Open this post in threaded view
|

Re: How to draw an ellipse using Octave

Carlo de Falco-2


> On 17 Jan 2019, at 15:22, Pantxo <[hidden email]> wrote:
>
> Or you can draw the ellipse yourself, which is not much longer:
>
> rx = 10; ry = 2;
>
> dx = linspace (0, rx, 100);
> dy = ry*sqrt (1-(dx./rx).^2);
>
> x = [dx fliplr(dx) -dx -fliplr(dx)];
> y = [dy -fliplr(dy) -dy fliplr(dy)];
> plot (x, y)
>
> Pantxo

Or, using a parametric representation :

rx = 10; ry = 2;
theta = linspace (0, 2*pi, 1000);
x = rx * cos (theta);
y = ry * sin (theta);
plot (x, y);

c.