Draw Filled Circle in Matlab
Introduction to Matlab Plot Circle
MATLAB can be used to perform operations involving geometric figures like circles, rectangles, squares etc. In this commodity, we will focus on circles. We will learn how to create various types of circles in MATLAB. We can create solid or aeroplane circles in MATLAB, which we will learn equally we become alee in the article. Nosotros will as well larn how to create a circle using the rectangle function.
How to Create a circle using Rectangle Role?
Let usa get-go learn syntax to draw a elementary circle in MATLAB:
1. Allow us first declare some points, here we are taking 500 points. The below code will create these points.
- angles = linspace(0, two*pi, 500);
2. Let us at present declare the radius and centre of the circle. The centre will be divers by 10 and y co-ordinates.
- radius = 20;
- CenterX = 50;
- CenterY = 40;
3. Finally, we will plot our circle.
- x = radius * cos(angles) + CenterX;
- y = radius * sin(angles) + CenterY;
4. Nosotros will also write some lawmaking for our output to await visually meliorate. This is normal formatting and we can adjust it as per our requirement.
- plot(x, y, 'b-', 'LineWidth', ii);
- concord on;
- plot(CenterX, CenterY, 'g+', 'LineWidth', iii, 'MarkerSize', 14);
- grid on;
- centrality equal;
- xlabel('X', 'FontSize', 14);
- ylabel('Y', 'FontSize', 14);
v. This is how our input and output will look like in MATLAB console:
Code:
angles = linspace(0, 2*pi, 500);
radius = 20;
CenterX = l;
CenterY = 40;
x = radius * cos(angles) + CenterX;
y = radius * sin(angles) + CenterY;
plot(x, y, 'b-', 'LineWidth', two);
hold on;
plot(CenterX, CenterY, 'm+', 'LineWidth', 3, 'MarkerSize', fourteen);
grid on;
centrality equal;
xlabel('X', 'FontSize', 14);
ylabel('Y', 'FontSize', fourteen);
Output:
As we can see in the above output, the circle is created with a radius 20 and centre (l, xl) every bit defined by us in the code.
How to Create a Solid 2D Circumvolve in MATLAB?
Next, let united states larn how to create a solid 2nd circumvolve in MATLAB:
i. Kickoff, we will exist creating logical prototype of circle. For this, we volition define eye, bore and the paradigm size. Permit us first create image.
- imageSizeOfX = 640;
- imageSizeOfY = 480;
- [colInImage rowsInImage] = meshgrid(ane : imageSizeOfX, i : imageSizeOfY);
two. Next, we volition be creating the circle inside the paradigm.
- centerOfX = 320;
- centerOfY = 240;
- radius = eighty;
- Pixels = (rowsInImage – centerOfY).^2 …
- + (colInImage – centerOfX).^2 <= radius.^ii;
3. In the above line of code, Pixels is "logical" array and is 2nd. Let united states now display 'Pixels'.
- image(Pixels);
- colormap([0 0 0; 1 i 1]);
- title('Prototype of circle');
4. This is how our input and output will look like in MATLAB console:
Code:
imageSizeOfX = 640;
imageSizeOfY = 480;
[colInImage rowsInImage] = meshgrid(i : imageSizeOfX, ane : imageSizeOfY);
centerOfX = 320;
centerOfY = 240;
radius = 80;
Pixels = (rowsInImage - centerOfY).^two ...
+ (colInImage - centerOfX).^ii <= radius.^2;
image(Pixels);
colormap([0 0 0; ane one ane]);
title('Image of circumvolve');
Output:
How to create a Circle in MATLAB Using Rectangle Function?
Let us now learn how to create a circle in MATLAB using rectangle function: Here is a elementary code to achieve this:
1. Similar we discussed in above examples, we will declare the radius and center co-ordinates of the required circle.
- radius = 6;
- centerX = 30;
- centerY = 40;
- rectangle('Position',[centerX – radius, centerY – radius, radius*2, radius*2],…
- 'Curvature',[1,1],…
- 'FaceColor','b');
- axis square;
two. We have passed 'FaceColor' equally "b" so our output circle will be of Bluish color.
Lawmaking:
radius = 6;
centerX = 30;
centerY = 40;
rectangle('Position',[centerX - radius, centerY - radius, radius*ii, radius*2],...
'Curvature',[1,1],...
'FaceColor','b');
axis square;
Output:
How we can Create a Simple arc in MATLAB?
Finally, allow the states discuss how we can create a simple arc in MATLAB. Every bit we know that arc is zilch only a pocket-size portion of the circle, code for creating an arc is also very similar to that of creating a circle.
1. Showtime we define the parameters of required arc.
- xCenter = 1;
- yCenter = one;
- radius = 4;
2. Next, nosotros define the angle theta as required.
- theta = linspace(20, 100, fifty);
- ten = radius * cosd(theta) + xCenter;
- y = radius * sind(theta) + yCenter;
iii. Finally, we plot our defined points.
- plot(10, y, 'b-', 'LineWidth', 2);
- axis equal;
- filigree on;
Code:
xCenter = 1;
yCenter = 1;
radius = 4;
theta = linspace(twenty, 100, 50);
x = radius * cosd(theta) + xCenter;
y = radius * sind(theta) + yCenter;
plot(ten, y, 'b-', 'LineWidth', ii);
centrality equal;
grid on;
Output:
Conclusion
So, in this article, we learnt how to create circles in MATLAB. We can create both plane circles and solid circles in MATLAB. We as well learnt how we tin leverage the Rectangle function to plot circles in MATLAB. We can also format our circle as per our requirement.
Recommended Articles
This is a guide to Matlab Plot Circle. Here we talk over an introduction, how to Create a circle using rectangle function, a Solid 2nd Circle, a circle in MATLAB and Elementary arc. Y'all tin can too go through our other related articles to acquire more –
- Intermission in MATLAB
- Nested Loop in Matlab
- Matlab pcolor() | Examples
- Complete Guide to Optimset Matlab
- Plot Vector Matlab | Functions
- Matlab Effigy | Examples
- xlabel Matlab | Examples
Source: https://www.educba.com/matlab-plot-circle/
0 Response to "Draw Filled Circle in Matlab"
Post a Comment