# Thread: [MATLAB] Delaunay/Veronoi Diagram - Get polygons

1. ## [MATLAB] Delaunay/Veronoi Diagram - Get polygons

I am trying to calculate polygons around nodes to provide criteria for where the nodes can move during an optimization routine I am working on. Nodes are restricted to the square region u={0,1} and v = {0,1}.

Here is the code for the attached image. It is simply a delaunay triangulation and veronoi diagram of 10 random node positions.

Code:
x = [0.196 0.992 0.802 0.424 0.729 0.498 0.809 0.357 0.073 0.591];
y = [0.910 0.194 0.432 0.749 0.039 0.946 0.764 0.559 0.184 0.498];
figure(1)
TRI = delaunay(x,y);
[vx, vy] = voronoi(x,y,TRI);
triplot(TRI,x,y,'k-')
axis([0 1 0 1]);
hold on;
plot(x,y,'r+',vx,vy,'b-','LineWidth',3)
hold off
txt = cell(1,length(x));
for j=1:length(x);txt{j}=sprintf('  %i',j);end
text(x,y,txt,'FontSize',18)
axis square
xlabel('u')
ylabel('v')
title('Optimizing Nodes in u-v Domain')
Idealy what I would like to achieve is an array for the position of each voronoi point and a cell array containing the indexes of each point corresponding to each nodes polygon or voronoi cell depending on what you want to call it. All veronoi points must be within / lie on the square region and each node must be completely bound.

I can do something like this which will return something close to what I want for the bound cells ONLY (it also return points outside the bounds I am interested in):

Code:
[V,C] = voronoin(unique([vx(:) vy(:)],'rows'));
figure(2)
cla
hold on
for j = 1:length(C)
patch('faces',C{j},'vertices',V)
end
hold off
Is there an efficient way to find out the bound regions of each node by also considering the boundaries u={0,1} and v = {0,1}. I am considering using this for an optimization routine I am working on where no node can be moved outside its veronoi cell within 1 iteration to prevent 2 nodes occupying the same possition so it is important that I can find a way to make sure each node has a corresponding "bound" cell consisting of points in the range u={0,1} and v = {0,1}.

I hope I have been clear enough, Please let me know if I need to post up more information.

Regards Elbarto
Attached Thumbnails
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 1, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "math_score": 0.46075859665870667, "perplexity": 840.6999798100549}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 20, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "warc_path": "s3://commoncrawl/crawl-data/CC-MAIN-2017-17/segments/1492917118831.16/warc/CC-MAIN-20170423031158-00059-ip-10-145-167-34.ec2.internal.warc.gz"}