Boolean operations with polyshape objects
Mostrar comentarios más antiguos
Hello everyone, I am trying to subtract a sector from a circle but I am getting some unwanted cut in the result as highlighted in red in the attached image. Please how may I remove this? Or is there a better way to achieve the same thing? Your help is very much appreciated
Below is the code.
r1 = 1.5; sec_ang=40; sec_ang=sec_ang*pi/180;
beta=60; beta= beta*pi/180; r2 = r1 + 2;
beta = beta*ones(1,2); % rotation angle
sec_ang = sec_ang*ones(1,2); % sectorial angle
r = [r1, r2] ; % radii
x0 = 0; y0 = 0;
theta = 0:pi/360:2*pi;
geom=[];
for i = 1:length(r)
circ = [r(i)*cos(theta)+x0 ; r(i)*sin(theta)+y0]; % generate points on the circle
a1 = beta(i); % start angle of arc
a2 = a1 + sec_ang(i); % end angle of arc
t = linspace(a1, a2);
xy = [x0 + (r(i)+1e-2)*cos(t); y0 + (r(i)+1e-2)*sin(t)]; % points on the arc of a sector
poly_sec= polyshape([x0,xy(1,:),x0], [y0, xy(2,:), y0]); %generate sector
p_circ = polyshape(circ(1,:), circ(2,:));
p_sub=subtract(p_circ,poly_sec); % subtract the sector from the circle
geom = [geom, p_sub.Vertices'];
end
p = polyshape(geom(1,:), geom(2,:));
plot(p,'FaceColor', 'k','LineWidth', 2)
axis equal
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Surface and Mesh Plots en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

