how i can draw a sector of a circle in matlab?
31 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
vatankhah
am 15 Dez. 2014
Beantwortet: Hamidullah Riaz
am 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 Kommentare
Akzeptierte Antwort
Roger Stafford
am 16 Dez. 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 Kommentare
Roger Stafford
am 25 Mai 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.
Weitere Antworten (2)
Adam
am 15 Dez. 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 Kommentare
Hamidullah Riaz
am 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 Kommentare
Siehe auch
Kategorien
Mehr zu Data Distribution Plots finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!