Borrar filtros
Borrar filtros

How do you create values for random points generated?

2 visualizaciones (últimos 30 días)
Ian Bouchard
Ian Bouchard el 30 de Nov. de 2017
I am currently attempting to randomly assign a value of 0 or 1 to the random points generated inside of the polygon, however I have no idea how to properly approach this and keep messing up. The initial points created I want to have their values set to 0 or 1, and then after finding the incenter of the delaunay triangles, have the incenter point be the average of selected points used to create each triangle. If anyone could possibly help me out with this that would be greatly appreciated! If it would be possible to also show the values of the incenter points would be amazing as well.
P.S. The polygon database is already provided in MATLAB and I have received much help from others in creating this code.
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)
hold on
triplot(dt, '--g')
triplot(dt1, '--r')
[XV, YV] = voronoi(IC(:,1),IC(:,2 ));
plot(XV,YV,'k')
axis([min(stX) max(stX) min(stY) max(stY)])

Respuestas (0)

Categorías

Más información sobre Delaunay Triangulation 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