Effacer les filtres
Effacer les filtres

Creating a voronoi diagram from incenter points of delaunay traingulation

1 vue (au cours des 30 derniers jours)
Ian Bouchard
Ian Bouchard le 30 Nov 2017
Commenté : KSSV le 30 Nov 2017
I am currently trying to create a voronoi diagram off of the incenter points of the delaunay triangulation but I am having a hard time getting the diagram of the voronoi to appear. I also want to confine the diagram within the polygon that I am using but I seem to be failing. Thank you for your help!!
P.S. The .shp file is already in MATLAB's database. I also have received a lot of help with this code from others.
states = shaperead('usastatehi.shp');
st = states(47); %creates a polgon in the shape of Washington State
stBB = st.BoundingBox;
st_minlat = min(stBB(:,2 ));
st_maxlat = max(stBB(:,2 ));
st_latspan = st_maxlat - st_minlat;
st_minlong = min(stBB(:,1 ));
st_maxlong = max(stBB(:,1 ));
st_longspan = st_maxlong - st_minlong;
stX = st.X ;
stY = st.Y;
numPointsIn = 42;
for i = 1:numPointsIn
flagIsIn = 0;
while ~flagIsIn
x(i) = st_minlong + rand(1) * st_longspan ;
y(i) = st_minlat + rand(1) * st_latspan ;
flagIsIn = inpolygon(x(i), y(i), stX, stY );
end
end
mapshow(st, 'edgecolor', 'r', 'facecolor', 'none ')
hold on
scatter(x, y , '.')
dt=delaunayTriangulation(x',y')
IC=incenter(dt)
dt1=delaunayTriangulation(IC)
voronoiDiagram(IC)
hold on
triplot(IC)

Réponse acceptée

KSSV
KSSV le 30 Nov 2017
Modifié(e) : KSSV le 30 Nov 2017
states = shaperead('usastatehi.shp');
st = states(47); %creates a polgon in the shape of Washington State
stBB = st.BoundingBox;
st_minlat = min(stBB(:,2 ));
st_maxlat = max(stBB(:,2 ));
st_latspan = st_maxlat - st_minlat;
st_minlong = min(stBB(:,1 ));
st_maxlong = max(stBB(:,1 ));
st_longspan = st_maxlong - st_minlong;
stX = st.X ;
stY = st.Y;
numPointsIn = 42;
for i = 1:numPointsIn
flagIsIn = 0;
while ~flagIsIn
x(i) = st_minlong + rand(1) * st_longspan ;
y(i) = st_minlat + rand(1) * st_latspan ;
flagIsIn = inpolygon(x(i), y(i), stX, stY );
end
end
mapshow(st, 'edgecolor', 'r', 'facecolor', 'none ')
hold on
scatter(x, y , '.')
%
dt=delaunayTriangulation(x',y')
IC=incenter(dt) ;
hold on
triplot(dt)
%
[XV, YV] = voronoi(IC(:,1),IC(:,2));
plot(XV,YV,'g')
axis([min(stX) max(stX) min(stY) max(stY)])
  2 commentaires
Ian Bouchard
Ian Bouchard le 30 Nov 2017
Once again thank you for the help!
KSSV
KSSV le 30 Nov 2017
You are welcome.....:)

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Delaunay Triangulation dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by