Drawing a segment of a circle
Mostra commenti meno recenti
I would like to draw a segment of a circle (like a slice of a pizza) but cannot find an easy way to do it.
I am currently drawing triangles using fill function but ideally I need one side of the triangle to be curved. Is there a way to specify a curvature of a line? Thanks B
Risposta accettata
Più risposte (1)
Matt Fig
il 27 Apr 2011
Here is another function to do it. It returns the handle to the patch object so that the color can be set or whatever.
function P = plot_arc(a,b,h,k,r)
% Plot a circular arc as a pie wedge.
% a is start of arc in radians,
% b is end of arc in radians,
% (h,k) is the center of the circle.
% r is the radius.
% Try this: plot_arc(pi/4,3*pi/4,9,-4,3)
% Author: Matt Fig
t = linspace(a,b);
x = r*cos(t) + h;
y = r*sin(t) + k;
x = [x h x(1)];
y = [y k y(1)];
P = fill(x,y,'r');
axis([h-r-1 h+r+1 k-r-1 k+r+1])
axis square;
if ~nargout
clear P
end
Now from the command line:
P = plot_arc(pi/4,3*pi/3,9,-4,3);
set(P,'edgecolor','b','linewidth',4)
7 Commenti
Bojan
il 27 Apr 2011
Bojan
il 27 Apr 2011
Matt Fig
il 27 Apr 2011
Simply use FILL instead of PLOT.
Matt Fig
il 27 Apr 2011
See my edited code above...
Bojan
il 27 Apr 2011
Ron Beck
il 26 Feb 2018
Is it possible to have a curve at the bottom instead of a point?
zain ul haq
il 23 Dic 2019
Sir, can I plot the segmet with height too, I need to plot like a 3d slice of a cake
Categorie
Scopri di più su Polar Plots in Centro assistenza e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!