How to display a circle with Matlab?
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.
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.
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.
| # | ID | Query | URL | Count |
|---|---|---|---|---|
| 0 | 13401 | alphons | https://en.ans.wiki/5647/how-to-display-a-circle-with-matlab | 1 |
| 1 | 12393 | en | https://en.ans.wiki/5647/how-to-display-a-circle-with-matlab | 6 |