How to draw a circle in GNU Octave

In Matlab, you can draw a circle by simply specifying the center and radius as follows:

R = 10; Center = [5,8]; circle(Center,R,1000,'b-'); hold on plot(Center(1),Center(2),'g.') 

The same code for MatLab will not work for GNU Octave. What octave code would a circle draw with the given x, y coordinates and radius?

+10
source share
7 answers
 t = linspace(0,2*pi,100)'; circsx = r.*cos(t) + x; circsy = r.*sin(t) + y; plot(circsx,circsy); 
+13
source

Using the optional octave-geometry octave package, you can use the drawCircle function like.

 drawCircle(x_position, y_position, radius) 
  1. Download the package from https://octave.sourceforge.io/geometry/
  2. In octave:
    • pkg install path_to_file.tar.gz
    • pkg load geometry
+6
source

If you want to use the reusable function, there is one possibility:

 function [h, hc] = circles(x,y,r,cmrk) % CIRCLES plot 2-D circles, given a set of center coordinates and radii. % % Description: % % Plot 2-D circles, given a set of center coordinates and radii. Values % can be vectors or matrices, as long as dimensions are consistent. If % a marker type (eg '+') is also given, circle centers will be marked % with it. The function returns a vector of handles for each circle and % a handle for all the center markers, if plotted. assert(size(x)==size(y), 'Mismatching sizes') assert(size(y)==size(r), 'Mismatching sizes') if (nargin==4) hc = scatter(x,y,[],[],cmrk); end axis([min(xr) max(x+r) min(yr) max(y+r)], 'equal'); a = linspace(0, 2*pi, 12); dx = sin(a); dy = cos(a); hold on for i=1:numel(x); h(i) = line(x(i)+dx*r(i), y(i)+dy*r(i)); end hold off 

Here is a usage example:

 x = 0:.1:2*pi; y = sin(x); r = rand(size(x))*.3; circles(x, y, r, '+') 
+4
source

How to draw a circle in the octave version of gnu version 3.8:

enter image description here

The code:

 octave> x = -1:0.01:1; octave> y = (1 - x .^ 2) .^ 0.5; octave> plot(x,y, "linewidth", 4, x,-y, "linewidth", 4); 

verbalization:

Create a list between -1 and 1 in increments of .01 to represent the x axis. The y axis is the diameter of the circle minus the value at each x-square index, all raised to 0.5 .

Graph x and y (blue), which gives the top half of the circle, then point x to -y, which inverts the top (green), creating the bottom half of the circle.

Alternatively use linspace:

enter image description here

The code:

 octave> r = 1; octave> t = linspace(0,2.*pi,1); octave> circsx = r.*cos(t) + x; octave> circsy = r.*sin(t) + y; octave> plot(circsx,circsy, "linewidth", 4, circsx, -circsy, "linewidth", 4); 

verbalization:

Draws a circle.

+3
source

Build a circle in GNU Octave:

 x = -3:0.01:3; y = (4 - x .^ 2) .^ 0.5; figure; plot(x,y); hold on; plot(x,-y); 

This should draw a circle with the equation x ^ 2 + y ^ 2 = 4;

+1
source

The geometry package has a built-in function that can be used to draw different geometric shapes. Here is the code for the circle:

 pkg load geometry drawCircle (x0, y0, r) 
0
source

Ocatve has several ways to draw a circle, this is one of the easiest ways.

 pkg load geometry x=0; y=0; #center point ordered pair r1=10; #radius of circule h1=drawCircle(x,y,r1); 

if you want the drow to spin

 hold on; r2=8; h2=drawCircle(x,y,r2); 

enter image description here

Another way is

 angle=linspace(0,2*pi,360); r=5; #radius x=2; y=5; #x and y is hear center point horizantalValue=r*cos(angle)+x; verticalValue=r*sin(angle)+y; plot(verticalValue,horizantalValue); 
0
source

All Articles