how i can draw a sector of a circle in matlab?

56 次查看(过去 30 天)
I want to draw a sector of a circle. The angle and the coordinate of sector's center are specified but the direction of the angle is random. i should mention that i need this pie to be a complete one, not just the curved part. like one of the pieces in this command:
pie([2 4 3 5],{'North','South','East','West'})
could anyone help me for the code please?

采纳的回答

Roger Stafford
Roger Stafford 2014-12-16
Let r be the circle's radius, P0 = [x0,y0] be its center, and theta be the required angle in radians.
a1 = 2*pi*rand; % A random direction
a2 = a1 + theta;
t = linspace(a1,a2);
x = x0 + r*cos(t);
y = y0 + r*sin(t);
plot([x0,x,x0],[y0,y,y0],'y-')
axis equal
  3 个评论
SaN AruL
SaN AruL 2016-5-25
编辑:SaN AruL 2016-5-25
shows error Undefined function or variable 'theta'.
Roger Stafford
Roger Stafford 2016-5-25
@SaN AruL: Look at the description of the problem, “Let r be the circle's radius, P0 = [x0,y0] be its center, and theta be the required angle in radians.” Theta, along with the radius, r, and the center P0 = [x0,y0] are assumed to be specified prior to the execution of the code. Theta is the assumed angle the circular sector.

请先登录,再进行评论。

更多回答(2 个)

Adam
Adam 2014-12-15
I don't have time to give complete code and it isn't an area I have much expertise in, but the following example shows how you can plot a sector.
t = linspace(0,0.5*pi,128);
x = [0 cos(t) 0];
y = [0 sin(t) 0];
figure; patch( x, y, 'r' )
You can obviously change the range in t to suit start and end angles as you please and use the help to look further into patch or this blog post may provide some further help even though it heads off in a different direction:

Hamidullah Riaz
Hamidullah Riaz 2021-8-19
With a little manipulation:
x0=0;
y0=0;
theta=0.25*pi;
a1 = 2*pi*rand; % A random direction
r=100; % radius
a2 = a1 + theta;
t = linspace(a1,a2);
x = x0 + r*cos(t);
y = y0 + r*sin(t);
plot([x0,x,x0],[y0,y,y0],'y-')
axis equal

类别

Help CenterFile Exchange 中查找有关 Data Distribution Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by