Create a new vector to set identity of each cell in Voronoi Diagram
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hi,
I wonder if anyone can please help me to solve the following issue:
I have two vectors X and Y, which create voronoi diagram. I will have to represent three types of cells (S, L and R) in the voronoi tessellation. To that end, I will have to generate another vector say C, which will set the identity of each voronoi cell i.e. three types of cells in the lattice.
For instance, X=[ 1.344 Y=[4.3301 C=[ 0
2.331 -1.2204 1
-2.194] 2.3210] 2]
where, 0 means 'S' cells, 1 means 'L' cells and 2 means 'R' cells or something like that.
Can anyone please help me to create a vector C, which will set the identity of each cell?
Actually, in a column vector, I will have to design like these data points are for these types of cells and these data points are for these types of cells (like S, L, R) and then show those distinct types of cells in the diagram.
So far, my attempt is attached here. Please help me to sort it out.
0 comentarios
Respuestas (1)
Scott MacKenzie
el 1 de Mayo de 2023
Editada: Scott MacKenzie
el 2 de Mayo de 2023
If I understand correctly, C -- the type of each cell -- identifies the corresponding quadrant for each point. You also want to show each type in the diagram. Here's a script to do this using a different fill color for each cell type:
load test_data % load X and Y (data in script posted in question)
% compute C to identify each cell as S, L, or R, as in question
S = X >= 0 & Y >= 0;
L = X > 0 & Y < 0;
R = X < 0 & Y > 0;
C = 0*S + 1*L + 2*R;
% get voronoi verticies (v) and cells (c) for data set
[v, c] = voronoin([X Y]);
% create basic voronoi figure from data in question
voronoi(X,Y);
axis([-4.1 4.1 -4 4]);
% color the cells to show type
hold on;
for i=1:length(X)
% get verticies of next polygon
px = v(c{i},1);
py = v(c{i},2);
% choose a color, as per cell type
switch C(i)
case 0
clr = [.9 .8 .7]; % S
case 1
clr = [.7 .8 .9]; % L
case 2
clr = [.8 .7 .9]; % R
end
% fill the polygon to show cell type
fill(px, py, clr, 'FaceAlpha', 0.5);
end
0 comentarios
Ver también
Categorías
Más información sobre Voronoi Diagram 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!