How do you create delaunay triangulation for random points inside a polygon
Ältere Kommentare anzeigen
I am having a very hard time trying to create a delaunay triangulation constrained by the borders of the provided polygon using the random points generated inside of my polygon. Provided below is my attempt, however I feel I a far from correct. (I also received help on this code below to get to where I am at now) Thank you!
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(i),y(i))
hold on
3 Kommentare
KSSV
am 30 Nov. 2017
.shp file is missing..we cannot run the code unless file is given. Attach your file here.
Ian Bouchard
am 30 Nov. 2017
KSSV
am 30 Nov. 2017
Ohh...cool..if it is inbuilt..no problem......will get back to the answer.
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Triangulations finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!