Drawing a segment of a circle

조회 수: 71 (최근 30일)
Bojan
Bojan 2011년 4월 27일
댓글: zain ul haq 2019년 12월 23일
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

채택된 답변

the cyclist
the cyclist 2011년 4월 27일
There are several files in the File Exchange that will do what you want. Here is one:
Also, here is a simple function that could be modified to draw just a segment:
function h = circle(x,y,r,nsegments)
if nargin<4
nsegments=50;
end
hold on
th = 0:2*pi/nsegments:2*pi;
xunit = r * cos(th) + x;
yunit = r * sin(th) + y;
h = plot(xunit, yunit);
hold off
end
  댓글 수: 1
poonam tailor
poonam tailor 2015년 1월 31일
Sir i need sector's center point. As i need a mid region of a circles sector for cluster head selection.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Matt Fig
Matt Fig 2011년 4월 27일
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
Ron Beck
Ron Beck 2018년 2월 26일
Is it possible to have a curve at the bottom instead of a point?
zain ul haq
zain ul haq 2019년 12월 23일
Sir, can I plot the segmet with height too, I need to plot like a 3d slice of a cake

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Lighting, Transparency, and Shading에 대해 자세히 알아보기

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by