color area between two shapes

3 visualizaciones (últimos 30 días)
Khoder Makkawi
Khoder Makkawi el 21 de Abr. de 2021
Comentada: Khoder Makkawi el 22 de Abr. de 2021
I have two shapes and I want to color the area between them
The first shape is a circle of Radius R=10 for example and with center (0,0), and the second shape is a random shape but surrounds the cirle and may have communs points, but it is impossible to have points inside the circle (as in the picture).
As example for real data that I have:
load('data.mat'); % load the coordinates of the second random shape represented as 'xfs' and 'yfs'
%%%%%%%%% create the circle %%%%%%%%%%
R = 10; C = [0. 0.] ;
xcf = C(1)+R*cos(linspace(0,2*pi,length(xfs))) ;
ycf = C(2)+R*sin(linspace(0,2*pi,length(xfs))) ;
  6 comentarios
Matt J
Matt J el 22 de Abr. de 2021
Let's plot it right now:
load(websave('t','https://www.mathworks.com/matlabcentral/answers/uploaded_files/592700/data.mat'))
scatter(xfs,yfs)
Khoder Makkawi
Khoder Makkawi el 22 de Abr. de 2021
It was the wrong data I saved in the second time sorry again.
These are the right coordinates.
I modified the file.

Iniciar sesión para comentar.

Respuesta aceptada

Matt J
Matt J el 22 de Abr. de 2021
Editada: Matt J el 22 de Abr. de 2021
load(websave('t','https://www.mathworks.com/matlabcentral/answers/uploaded_files/592785/data.mat'))
R = 10; C = [0. 0.] ;
xcf = C(1)+R*cos(linspace(0,2*pi,length(xfs))) ;
ycf = C(2)+R*sin(linspace(0,2*pi,length(xfs))) ;
shpOuter=polyshape(xfs,yfs);
shpInner=polyshape(xcf,ycf);
Warning: Polyshape has duplicate vertices, intersections, or other inconsistencies that may produce inaccurate or unexpected results. Input data has been modified to create a well-defined polyshape.
plot(shpOuter,'FaceColor','none');
hold on
plot(shpInner,'FaceColor','none');
plot(subtract(shpOuter,shpInner))
hold off
  5 comentarios
Matt J
Matt J el 22 de Abr. de 2021
No. You should upgrade. There have been lots of important new features added since R2016a.
Khoder Makkawi
Khoder Makkawi el 22 de Abr. de 2021
ok Thank you I will try to upgrade.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Elementary Polygons 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!

Translated by