Draw Circle on Map Matlab
Introduction to Matlab Plot Circle
MATLAB can be used to perform operations involving geometric figures like circles, rectangles, squares etc. In this article, we volition focus on circles. We volition acquire how to create various types of circles in MATLAB. We can create solid or plane circles in MATLAB, which we will learn as we go ahead in the commodity. We will likewise learn how to create a circumvolve using the rectangle function.
How to Create a circle using Rectangle Function?
Let us first learn syntax to describe a unproblematic circle in MATLAB:
1. Permit us first declare some points, here we are taking 500 points. The beneath code volition create these points.
- angles = linspace(0, two*pi, 500);
2. Let united states of america now declare the radius and center of the circle. The heart volition be defined by 10 and y co-ordinates.
- radius = xx;
- CenterX = 50;
- CenterY = xl;
3. Finally, nosotros will plot our circle.
- x = radius * cos(angles) + CenterX;
- y = radius * sin(angles) + CenterY;
iv. We will likewise write some code for our output to look visually ameliorate. This is normal formatting and nosotros tin adjust it as per our requirement.
- plot(x, y, 'b-', 'LineWidth', two);
- concur on;
- plot(CenterX, CenterY, 'yard+', 'LineWidth', 3, 'MarkerSize', 14);
- grid on;
- axis equal;
- xlabel('X', 'FontSize', 14);
- ylabel('Y', 'FontSize', 14);
five. This is how our input and output will look like in MATLAB console:
Lawmaking:
angles = linspace(0, 2*pi, 500);
radius = 20;
CenterX = l;
CenterY = 40;
x = radius * cos(angles) + CenterX;
y = radius * sin(angles) + CenterY;
plot(ten, y, 'b-', 'LineWidth', ii);
hold on;
plot(CenterX, CenterY, 'yard+', 'LineWidth', 3, 'MarkerSize', xiv);
grid on;
axis equal;
xlabel('X', 'FontSize', 14);
ylabel('Y', 'FontSize', xiv);
Output:
As we can run across in the above output, the circle is created with a radius 20 and centre (fifty, twoscore) equally defined by us in the code.
How to Create a Solid 2d Circle in MATLAB?
Next, permit us acquire how to create a solid 2nd circle in MATLAB:
1. First, nosotros will be creating logical image of circle. For this, nosotros volition define center, bore and the image size. Let us beginning create image.
- imageSizeOfX = 640;
- imageSizeOfY = 480;
- [colInImage rowsInImage] = meshgrid(i : imageSizeOfX, 1 : imageSizeOfY);
2. Next, we will exist creating the circle within the image.
- centerOfX = 320;
- centerOfY = 240;
- radius = 80;
- Pixels = (rowsInImage – centerOfY).^2 …
- + (colInImage – centerOfX).^two <= radius.^2;
three. In the above line of lawmaking, Pixels is "logical" array and is 2nd. Permit us now display 'Pixels'.
- image(Pixels);
- colormap([0 0 0; 1 one 1]);
- title('Image of circle');
4. This is how our input and output will look like in MATLAB console:
Code:
imageSizeOfX = 640;
imageSizeOfY = 480;
[colInImage rowsInImage] = meshgrid(ane : imageSizeOfX, 1 : imageSizeOfY);
centerOfX = 320;
centerOfY = 240;
radius = 80;
Pixels = (rowsInImage - centerOfY).^2 ...
+ (colInImage - centerOfX).^2 <= radius.^2;
prototype(Pixels);
colormap([0 0 0; 1 1 1]);
championship('Image of circle');
Output:
How to create a Circle in MATLAB Using Rectangle Function?
Let the states now acquire how to create a circle in MATLAB using rectangle part: Here is a simple code to achieve this:
1. Like we discussed in higher up examples, we will declare the radius and centre co-ordinates of the required circle.
- radius = 6;
- centerX = 30;
- centerY = 40;
- rectangle('Position',[centerX – radius, centerY – radius, radius*ii, radius*2],…
- 'Curvature',[1,ane],…
- 'FaceColor','b');
- axis square;
2. We have passed 'FaceColor' equally "b" so our output circle will be of Blue color.
Code:
radius = 6;
centerX = xxx;
centerY = 40;
rectangle('Position',[centerX - radius, centerY - radius, radius*2, radius*ii],...
'Curvature',[1,1],...
'FaceColor','b');
axis square;
Output:
How we can Create a Unproblematic arc in MATLAB?
Finally, permit usa talk over how we can create a simple arc in MATLAB. Every bit we know that arc is zero but a small portion of the circle, code for creating an arc is likewise very like to that of creating a circle.
1. First nosotros define the parameters of required arc.
- xCenter = 1;
- yCenter = i;
- radius = iv;
2. Next, we define the angle theta equally required.
- theta = linspace(20, 100, 50);
- x = radius * cosd(theta) + xCenter;
- y = radius * sind(theta) + yCenter;
3. Finally, we plot our defined points.
- plot(x, y, 'b-', 'LineWidth', two);
- axis equal;
- grid on;
Lawmaking:
xCenter = ane;
yCenter = 1;
radius = four;
theta = linspace(twenty, 100, 50);
x = radius * cosd(theta) + xCenter;
y = radius * sind(theta) + yCenter;
plot(ten, y, 'b-', 'LineWidth', 2);
axis equal;
filigree on;
Output:
Determination
So, in this article, we learnt how to create circles in MATLAB. We can create both plane circles and solid circles in MATLAB. We also learnt how nosotros can leverage the Rectangle function to plot circles in MATLAB. We tin can also format our circumvolve as per our requirement.
Recommended Articles
This is a guide to Matlab Plot Circle. Here nosotros hash out an introduction, how to Create a circle using rectangle role, a Solid 2d Circumvolve, a circumvolve in MATLAB and Simple arc. You lot can likewise go through our other related manufactures to learn more –
- Break in MATLAB
- Nested Loop in Matlab
- Matlab pcolor() | Examples
- Complete Guide to Optimset Matlab
- Plot Vector Matlab | Functions
- Matlab Figure | Examples
- xlabel Matlab | Examples
Source: https://www.educba.com/matlab-plot-circle/
Post a Comment for "Draw Circle on Map Matlab"