Draw a Circle Using Two Points

Matlab Plot Circle

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 will acquire how to create various types of circles in MATLAB. We tin create solid or plane circles in MATLAB, which we volition larn every bit nosotros go ahead in the article. Nosotros volition too learn how to create a circle using the rectangle role.

How to Create a circle using Rectangle Function?

Allow us commencement learn syntax to draw a unproblematic circle in MATLAB:

1. Let united states of america showtime declare some points, hither we are taking 500 points. The below code will create these points.

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

2. Let us now declare the radius and center of the circle. The eye will be defined by x and y co-ordinates.

  • radius = 20;
  • CenterX = l;
  • CenterY = forty;

3. Finally, we will plot our circle.

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

4. We volition also write some code for our output to look visually ameliorate. This is normal formatting and nosotros can adapt it equally per our requirement.

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

v. This is how our input and output volition look like in MATLAB console:

Code:

angles = linspace(0, two*pi, 500);
radius = 20;
CenterX = l;
CenterY = xl;
x = radius * cos(angles) + CenterX;
y = radius * sin(angles) + CenterY;
plot(x, y, 'b-', 'LineWidth', 2);
hold on;
plot(CenterX, CenterY, 'thousand+', 'LineWidth', 3, 'MarkerSize', xiv);
grid on;
axis equal;
xlabel('X', 'FontSize', 14);
ylabel('Y', 'FontSize', 14);

Output:

Matlab Plot Circle - 1

As nosotros tin see in the above output, the circumvolve is created with a radius 20 and centre (50, 40) as defined by u.s. in the code.

How to Create a Solid second Circle in MATLAB?

Next, let us learn how to create a solid 2D circle in MATLAB:

i. First, we volition be creating logical image of circle. For this, we will define centre, diameter and the image size. Let us first create image.

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

two. Next, nosotros will be creating the circle inside the image.

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

3. In the higher up line of lawmaking, Pixels is "logical" array and is 2D. Let us now display 'Pixels'.

  • image(Pixels);
  • colormap([0 0 0; 1 i one]);
  • title('Paradigm of circle');

four. This is how our input and output will look like in MATLAB panel:

Code:

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

Output:

Matlab Plot Circle - 2

How to create a Circle in MATLAB Using Rectangle Part?

Permit united states of america now learn how to create a circle in MATLAB using rectangle role: Here is a unproblematic code to accomplish this:

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

  • radius = half dozen;
  • centerX = xxx;
  • centerY = 40;
  • rectangle('Position',[centerX – radius, centerY – radius, radius*ii, radius*two],…
  • 'Curvature',[one,one],…
  • 'FaceColor','b');
  • axis foursquare;

2. We have passed 'FaceColor' as "b" then our output circle will exist of Blue colour.

Code:

radius = six;
centerX = 30;
centerY = xl;
rectangle('Position',[centerX - radius, centerY - radius, radius*ii, radius*two],...
'Curvature',[i,i],...
'FaceColor','b');
centrality foursquare;

Output:

Rectangle Function

How nosotros can Create a Simple arc in MATLAB?

Finally, let us discuss how we can create a uncomplicated arc in MATLAB. Equally we know that arc is nothing but a minor portion of the circle, lawmaking for creating an arc is as well very similar to that of creating a circumvolve.

1. Outset we define the parameters of required arc.

  • xCenter = 1;
  • yCenter = 1;
  • radius = iv;

2. Adjacent, we ascertain the angle theta every bit required.

  • theta = linspace(20, 100, 50);
  • x = radius * cosd(theta) + xCenter;
  • y = radius * sind(theta) + yCenter;

3. Finally, nosotros plot our defined points.

  • plot(ten, y, 'b-', 'LineWidth', 2);
  • axis equal;
  • grid on;

Code:

xCenter = ane;
yCenter = ane;
radius = 4;
theta = linspace(20, 100, l);
x = radius * cosd(theta) + xCenter;
y = radius * sind(theta) + yCenter;
plot(ten, y, 'b-', 'LineWidth', 2);
axis equal;
grid on;

Output:

Simple arc

Conclusion

And so, in this article, we learnt how to create circles in MATLAB. We tin create both airplane circles and solid circles in MATLAB. We besides learnt how nosotros tin leverage the Rectangle function to plot circles in MATLAB. We tin as well format our circumvolve as per our requirement.

Recommended Articles

This is a guide to Matlab Plot Circumvolve. Hither we discuss an introduction, how to Create a circle using rectangle function, a Solid 2d Circle, a circle in MATLAB and Elementary arc. You tin can also go through our other related articles to learn more –

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

smithfouns1984.blogspot.com

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

0 Response to "Draw a Circle Using Two Points"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel