+ Create a function to draw circle

This commit is contained in:
Guillaume GIBERT 2021-11-29 22:30:49 +01:00
parent e7b06aba37
commit 81fd01d377
1 changed files with 30 additions and 0 deletions

30
drawCircle.m Normal file
View File

@ -0,0 +1,30 @@
function h = drawCircle(x,y,r)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% function h = drawCircle(x,y,r)
% Task: Draw a circle providing its center and radius
%
% Inputs:
% - x: the x-coordinate of the circle center (in m)
% - y: the y-coordinate of the circle center (in m)
% - r: the radius of the circle center (in m)
%
% Outputs:
% - h: a reference to the plot figure
%
%
% author: Guillaume Gibert, guillaume.gibert@ecam.fr
% date: 14/09/2021
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% holds the previous drawing
hold on;
% generates samples in the range [0, 2pi]
th = 0:pi/50:2*pi;
% computes (x,y) samples along the circle perimeter
xunit = r * cos(th) + x;
yunit = r * sin(th) + y;
% plots the samples
h = plot(xunit, yunit, 'r');