how i can draw a sector of a circle in matlab?
26 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
vatankhah
el 15 de Dic. de 2014
Respondida: Hamidullah Riaz
el 19 de Ag. de 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 comentarios
Respuesta aceptada
Roger Stafford
el 16 de Dic. de 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 comentarios
Roger Stafford
el 25 de Mayo de 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.
Más respuestas (2)
Adam
el 15 de Dic. de 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 comentarios
Hamidullah Riaz
el 19 de Ag. de 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 comentarios
Ver también
Categorías
Más información sobre Data Distribution Plots en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!