Draw a Circle of Unit Radius in Matlab

Matlab Plot Circle

Introduction to Matlab Plot Circle

MATLAB can exist used to perform operations involving geometric figures like circles, rectangles, squares etc. In this article, we will focus on circles. We volition larn how to create various types of circles in MATLAB. We can create solid or plane circles in MATLAB, which nosotros will learn equally nosotros go ahead in the article. Nosotros will also learn how to create a circle using the rectangle office.

How to Create a circle using Rectangle Role?

Let us first learn syntax to draw a simple circle in MATLAB:

one. Let us first declare some points, here nosotros are taking 500 points. The below lawmaking will create these points.

  • angles = linspace(0, 2*pi, 500);

2. Allow u.s.a. at present declare the radius and heart of the circle. The middle will exist defined by x and y co-ordinates.

  • radius = xx;
  • CenterX = 50;
  • CenterY = 40;

three. Finally, we will plot our circumvolve.

  • x = radius * cos(angles) + CenterX;
  • y = radius * sin(angles) + CenterY;

4. We will also write some code for our output to look visually better. This is normal formatting and nosotros can adjust it every bit per our requirement.

  • plot(x, y, 'b-', 'LineWidth', 2);
  • hold on;
  • plot(CenterX, CenterY, 'yard+', 'LineWidth', 3, 'MarkerSize', 14);
  • grid on;
  • axis equal;
  • xlabel('X', 'FontSize', 14);
  • ylabel('Y', 'FontSize', xiv);

5. This is how our input and output will look like in MATLAB console:

Code:

angles = linspace(0, ii*pi, 500);
radius = 20;
CenterX = 50;
CenterY = xl;
ten = radius * cos(angles) + CenterX;
y = radius * sin(angles) + CenterY;
plot(x, y, 'b-', 'LineWidth', 2);
hold on;
plot(CenterX, CenterY, 'm+', 'LineWidth', 3, 'MarkerSize', fourteen);
grid on;
axis equal;
xlabel('Ten', 'FontSize', 14);
ylabel('Y', 'FontSize', fourteen);

Output:

Matlab Plot Circle - 1

Equally we tin run across in the above output, the circumvolve is created with a radius 20 and eye (50, 40) every bit defined by u.s.a. in the code.

How to Create a Solid 2D Circumvolve in MATLAB?

Next, allow us larn how to create a solid 2D circle in MATLAB:

1. Get-go, we will be creating logical image of circle. For this, we will define center, diameter and the image size. Allow u.s. first create image.

  • imageSizeOfX = 640;
  • imageSizeOfY = 480;
  • [colInImage rowsInImage] = meshgrid(ane : imageSizeOfX, 1 : imageSizeOfY);

2. Next, we will be creating the circle within the paradigm.

  • centerOfX = 320;
  • centerOfY = 240;
  • radius = 80;
  • Pixels = (rowsInImage – centerOfY).^2 …
  • + (colInImage – centerOfX).^ii <= radius.^two;

3. In the above line of code, Pixels is "logical" array and is 2nd. Permit u.s. now display 'Pixels'.

  • prototype(Pixels);
  • colormap([0 0 0; 1 ane one]);
  • title('Epitome of circle');

4. This is how our input and output will expect like in MATLAB console:

Code:

imageSizeOfX = 640;
imageSizeOfY = 480;
[colInImage rowsInImage] = meshgrid(1 : imageSizeOfX, 1 : imageSizeOfY);
centerOfX = 320;
centerOfY = 240;
radius = fourscore;
Pixels = (rowsInImage - centerOfY).^2 ...
+ (colInImage - centerOfX).^2 <= radius.^2;
epitome(Pixels);
colormap([0 0 0; 1 one one]);
title('Image of circle');

Output:

Matlab Plot Circle - 2

How to create a Circle in MATLAB Using Rectangle Function?

Allow us now learn how to create a circle in MATLAB using rectangle function: Here is a simple code to achieve this:

1. Like we discussed in above examples, we volition declare the radius and middle co-ordinates of the required circle.

  • radius = half-dozen;
  • centerX = 30;
  • centerY = forty;
  • rectangle('Position',[centerX – radius, centerY – radius, radius*two, radius*2],…
  • 'Curvature',[1,one],…
  • 'FaceColor','b');
  • centrality square;

2. Nosotros have passed 'FaceColor' as "b" so our output circle will be of Blueish color.

Code:

radius = vi;
centerX = 30;
centerY = twoscore;
rectangle('Position',[centerX - radius, centerY - radius, radius*2, radius*ii],...
'Curvature',[i,1],...
'FaceColor','b');
axis square;

Output:

Rectangle Function

How we can Create a Simple arc in MATLAB?

Finally, permit usa discuss how nosotros tin create a elementary arc in MATLAB. As we know that arc is nothing but a small portion of the circumvolve, code for creating an arc is too very similar to that of creating a circle.

1. First we define the parameters of required arc.

  • xCenter = 1;
  • yCenter = one;
  • radius = 4;

2. Next, we define the angle theta as 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', 2);
  • axis equal;
  • grid on;

Lawmaking:

xCenter = 1;
yCenter = 1;
radius = iv;
theta = linspace(20, 100, 50);
10 = radius * cosd(theta) + xCenter;
y = radius * sind(theta) + yCenter;
plot(10, y, 'b-', 'LineWidth', 2);
axis equal;
grid on;

Output:

Simple arc

Conclusion

And so, in this commodity, we learnt how to create circles in MATLAB. We tin create both aeroplane circles and solid circles in MATLAB. Nosotros as well learnt how nosotros can leverage the Rectangle function to plot circles in MATLAB. Nosotros tin also format our circle every bit per our requirement.

Recommended Articles

This is a guide to Matlab Plot Circle. Here nosotros discuss an introduction, how to Create a circle using rectangle function, a Solid 2nd Circumvolve, a circle in MATLAB and Simple arc. Yous can likewise go through our other related articles to learn more –

  1. Break in MATLAB
  2. Nested Loop in Matlab
  3. Matlab pcolor() | Examples
  4. Complete Guide to Optimset Matlab
  5. Plot Vector Matlab | Functions
  6. Matlab Figure | Examples
  7. xlabel Matlab | Examples

andersongoiderink.blogspot.com

Source: https://www.educba.com/matlab-plot-circle/

0 Response to "Draw a Circle of Unit Radius in Matlab"

Publicar un comentario

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel