Question #5647   Submitted by Answiki on 01/04/2022 at 06:54:35 PM UTC

How to display a circle with Matlab?

Answer   Submitted by Answiki on 03/11/2022 at 06:33:22 PM UTC

There is no native function to draw a circle with Matlab. But there are several alternatives. The best solution is to create a circle() function that will draw the circle with center (Xc, Yc) and radius R:

% Xc et Yc sont les coordonnées du centre du cercle
% R est le rayon du cercle
function circle(Xc, Yc, R)
    % 0.01 est le pas d'échantillonnage en radians. 
    % En augmentant le pas :
    %  - le cercle sera plus lisse
    %  - mais la fonction sera ralentie
    theta=0:0.01:2*pi; 
    X=Xc+R*cos(theta);
    Y=Yc+R*sin(theta);
    plot(X, Y);
end


You can write the above function in a single as a function handle. This is very useful and compact:

% Handle function
drawCircle = @(C,R,color) plot ( C(1) + R*cos([0:0.01:2*pi]) , C(2) + R*sin([0:0.01:2*pi]), color );

% Draw a circle of center (3,2) and radius 2.4
drawCircle([3,2], 2.4, 'r');



If the drawing of a circle is punctual and does not require a function, it is possible to draw a circle with the following instruction (Xc, Yc and R must be defined or replaced by numerical values):

plot ( Xc + R*cos([0:0.01:2*pi]) , Yc + R*sin([0:0.01:2*pi]) )

Finally, there is a third solution, which consists of displaying a point with a round marker and changing the size of the marker :

plot (10, 20, 'o', 'MarkerSize', 50)

Note that the marker size is not the radius of the circle.

3 events in history
Answer by Answiki on 03/11/2022 at 06:33:22 PM

There is no native function to draw a circle with Matlab. But there are several alternatives. The best solution is to create a circle() function that will draw the circle with center (Xc, Yc) and radius R:

% Xc et Yc sont les coordonnées du centre du cercle
% R est le rayon du cercle
function circle(Xc, Yc, R)
    % 0.01 est le pas d'échantillonnage en radians. 
    % En augmentant le pas :
    %  - le cercle sera plus lisse
    %  - mais la fonction sera ralentie
    theta=0:0.01:2*pi; 
    X=Xc+R*cos(theta);
    Y=Yc+R*sin(theta);
    plot(X, Y);
end


You can write the above function in a single as a function handle. This is very useful and compact:

% Handle function
drawCircle = @(C,R,color) plot ( C(1) + R*cos([0:0.01:2*pi]) , C(2) + R*sin([0:0.01:2*pi]), color );

% Draw a circle of center (3,2) and radius 2.4
drawCircle([3,2], 2.4, 'r');



If the drawing of a circle is punctual and does not require a function, it is possible to draw a circle with the following instruction (Xc, Yc and R must be defined or replaced by numerical values):

plot ( Xc + R*cos([0:0.01:2*pi]) , Yc + R*sin([0:0.01:2*pi]) )

Finally, there is a third solution, which consists of displaying a point with a round marker and changing the size of the marker :

plot (10, 20, 'o', 'MarkerSize', 50)

Note that the marker size is not the radius of the circle.

Answer by Answiki on 01/04/2022 at 06:57:35 PM

There is no native function to draw a circle with Matlab. But there are several alternatives. The best solution is to create a circle() function that will draw the circle with center (Xc, Yc) and radius R:

% Xc et Yc sont les coordonnées du centre du cercle
% R est le rayon du cercle
function circle(Xc, Yc, R)
    % 0.01 est le pas d'échantillonnage en radians. 
    % En augmentant le pas :
    %  - le cercle sera plus lisse
    %  - mais la fonction sera ralentie
    theta=0:0.01:2*pi; 
    X=Xc+R*cos(theta);
    Y=Yc+R*sin(theta);
    plot(X, Y);
end

If the drawing of a circle is punctual and does not require a function, it is possible to draw a circle with the following instruction (Xc, Yc and R must be defined or replaced by numerical values):

plot ( Xc + R*cos([0:0.01:2*pi]) , Yc + R*sin([0:0.01:2*pi]) )

Finally, there is a third solution, which consists of displaying a point with a round marker and changing the size of the marker :

plot (10, 20, 'o', 'MarkerSize', 50)

Note that the marker size is not the radius of the circle.

Question by Answiki 01/04/2022 at 06:54:35 PM
How to display a circle with Matlab?
# ID Query URL Count

Icons proudly provided by Friconix.