how i can draw a sector of a circle in matlab?
26 views (last 30 days)
Show older comments
vatankhah
on 15 Dec 2014
Answered: Hamidullah Riaz
on 19 Aug 2021
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 Comments
Accepted Answer
Roger Stafford
on 16 Dec 2014
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 Comments
Roger Stafford
on 25 May 2016
@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.
More Answers (2)
Adam
on 15 Dec 2014
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 Comments
Hamidullah Riaz
on 19 Aug 2021
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 Comments
See Also
Categories
Find more on Data Distribution Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!