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?
0 个评论
采纳的回答
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 个评论
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
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:
0 个评论
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
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Distribution Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!