フィルターのクリア

How do you create delaunay triangulation for random points inside a polygon

2 ビュー (過去 30 日間)
Ian Bouchard
Ian Bouchard 2017 年 11 月 30 日
コメント済み: Ian Bouchard 2017 年 11 月 30 日
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 件のコメント
Ian Bouchard
Ian Bouchard 2017 年 11 月 30 日
usastatehi.shp? Please forgive my lack of coding knowledge in MATLAB but I am unable to figure out how to get the file. I have MATLAB R2017b and the .shp file is already saved in the database. Is there a way I can download the file?
KSSV
KSSV 2017 年 11 月 30 日
Ohh...cool..if it is inbuilt..no problem......will get back to the answer.

サインインしてコメントする。

採用された回答

KSSV
KSSV 2017 年 11 月 30 日
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') ;
hold on
triplot(dt) ;
If your idea is to m esh the entire region......then you should have a look here: https://in.mathworks.com/matlabcentral/fileexchange/25555-mesh2d-delaunay-based-unstructured-mesh-generation

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDelaunay Triangulation についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by