Bonjour, j'ai besoin d'obtenir des polygones autour des nœuds aléatoires en Matlab.
Y a-t-il une manière intéressante, une boucle par exemple, de déclarer les coordonnées des points ?
Merci
Version imprimable
Bonjour, j'ai besoin d'obtenir des polygones autour des nœuds aléatoires en Matlab.
Y a-t-il une manière intéressante, une boucle par exemple, de déclarer les coordonnées des points ?
Merci
Bonjour,
La question manque de précision : que sont les noeuds aléatoires? comment sont définis les polygones?
les nœuds sont des points dessinés aléatoirement ,je veux intégrer une polygone dans chaque cellule de voronoi.
Mon but est d'obtenir une figure comme celle-ci Pièce jointe 178304
j'ai déjà trouver celle-ci Pièce jointe 178305
L'étape suivante consiste à tirer une forme dans chaque polygone afin d'introduire une distance entre les polygones et aussi pour lisser les coins d'entre eux.
Si je comprends bien, tu veux arriver à obtenir les courbes qui sont à l'intérieur des cellules de Voronoï?
Ces courbes me rappellent un peu à des courbes de bezier ou les noeuds seraient les points de contrô
cette phrase n'est pas claire du tout: qu'entend-tu par "tirer une forme"? de quelle distance parles-tu?
Bonjour, c'est à dire je veux obtenir une forme quelconque dans chaque cellule de voronoi, et la distance entre les formes voisins soit calculés
Je ne vois vraiment pas ou tu veux en venir. Explique nous peut-être la finalité de ton étude, sinon on ne va pas s'en sortir.
Je déplace dans le forum algorithme car pour le moment, le problème n'a pas de lien avec matlab.
je veux écrire un code matlab qui me permet d'obtenir la 1ére image, mais je ne sais pas comment introduire les formes dans les cellules voronoi ?!
Avant de penser au code, il faut savoir comment obtenir ces formes! D'ou provient l'image?
j'ai utilisé fonction voronoi tesselation et voici le code :
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246 function [ p, t ] = cvt_square_uniform ( n, sample_num, delaunay_display) %*****************************************************************************80 % %% CVT_SQUARE_UNIFORM demonstrates how a CVT can be computed and displayed in MATLAB. % % Discussion: % % This simple example carries out an iterative CVT calculation in the % unit square, with a uniform density. The initial placement of the % generators is random. % % Licensing: % % This code is distributed under the GNU LGPL license. % % Modified: % % 22 May 2006 % % Author: % % John Burkardt % % Reference: % % Qiang Du, Vance Faber, Max Gunzburger, % Centroidal Voronoi Tessellations: Applications and Algorithms, % SIAM Review, % Volume 41, 1999, pages 637-676. % % Parameters: % % Input, integer N, the number of generators. % % Input, integer SAMPLE_NUM, the number of sample points. % % Input, logical DELAUNAY_DISPLAY, is TRUE (nonzero) if the Delaunay % triangulation is to be displayed. % % Output, real P(N,2), the location of the generators. % % Output, integer T(NT,3), information defining the Delaunay % triangulation of the generators. NT is the number of triangles, % which varies depending on the arrangement of the generators. % fprintf ( 1, '\n' ); fprintf ( 1, 'CVT_SQUARE_UNIFORM:\n' ); fprintf ( 1, ' A simple demonstration of a CVT computation\n' ); fprintf ( 1, ' (Centroidal Voronoi Tessellation)\n' ); fprintf ( 1, ' in a square, with a uniform density.\n' ); if ( nargin < 1 ) n = 100; fprintf ( 1, '\n' ); fprintf ( 1, 'CVT_SQUARE_UNIFORM - Note:\n' ); fprintf ( 1, ' No value of N was supplied.\n' ); fprintf ( 1, ' N is the number of generators.\n' ); fprintf ( 1, ' A default value N = %d will be used.\n', n ); else fprintf ( 1, '\n' ); fprintf ( 1, ' User specified number of generators = %d\n', n ); end if ( nargin < 2 ) sample_num = 1000 * n; fprintf ( 1, '\n' ); fprintf ( 1, 'CVT_SQUARE_UNIFORM - Note:\n' ); fprintf ( 1, ' No value of SAMPLE_NUM was supplied.\n' ); fprintf ( 1, ' SAMPLE_NUM is the number of sample points.\n' ); fprintf ( 1, ' A default value SAMPLE_NUM = %d will be used.\n', ... sample_num ); else fprintf ( 1, '\n' ); fprintf ( 1, ' User specified number of sample points = %d\n', ... sample_num ); end if ( nargin < 3 ) delaunay_display = 0; fprintf ( 1, '\n' ); fprintf ( 1, 'CVT_SQUARE_UNIFORM - Note:\n' ); fprintf ( 1, ' No value of DELAUNAY_DISPLAY was supplied.\n' ); fprintf ( 1, ' DELAUNAY_DISPLAY is TRUE (nonzero) if the\n' ); fprintf ( 1, ' Delaunay triangulation is also to be displayed.\n' ); fprintf ( 1, ' A default value DELAUNAY_DISPLAY = %d will be used.\n', ... delaunay_display ); else fprintf ( 1, '\n' ); fprintf ( 1, ' User specified DELAUNAY_DISPLAY = %d\n', ... delaunay_display ); end % % This switch is set to 1 (TRUE) if the ACCUMARRAY command is available. % That speeds up the calculation a lot. If you don't have the ACCUMARRAY % command, just set this to 0. % fprintf ( 1, '\n' ); fprintf ( 1, 'CVT_SQUARE_UNIFORM:\n' ); fprintf ( 1, ' MATLAB''s ACCUMARRAY command can be used for faster\n' ); fprintf ( 1, ' computation. This command is not available in\n' ); fprintf ( 1, ' some versions of MATLAB. If ACCUMARRAY is available,\n' ); fprintf ( 1, ' simply make sure that the ACCUMARAY_AVAILABLE variable\n' ); fprintf ( 1, ' is set to 1!\n' ); accumarray_available = 1; if ( accumarray_available ) fprintf ( 1, '\n' ); fprintf ( 1, ' The ACCUMARRAY command will be used.\n' ); else fprintf ( 1, '\n' ); fprintf ( 1, ' The ACCUMARRAY command will NOT be used.\n' ); end % % Clear the figure screen, if already open. % clf % Randomize the initial locations of the generators in the unit square. % If another region is used, then this initialization should be changed. p = rand ( n, 2 ); plot ( p(:,1), p(:,2), 'b.' ); axis ( [ 0.0, 1.0, 0.0, 1.0 ] ) line ( [ 0.0, 1.0, 1.0, 0.0, 0.0 ], [ 0.0, 0.0, 1.0, 1.0, 0.0 ], ... 'Color', 'r', 'LineWidth', 2 ); title_string = sprintf ( 'Initial Generators' ); title ( title_string ); axis equal drawnow string = input ( 'RETURN, or Q to quit: ', 's' ); if ( string == 'q' | string == 'Q' ) return end it = 0; while ( 1 ) % Compute the Delaunay triangle information T for the current nodes. t = delaunay ( p(:,1), p(:,2) ); % Display the Delaunay triangulation, if requested. if ( delaunay_display ) subplot ( 1, 2, 2 ) trimesh ( t, p(:,1), p(:,2), zeros(n,1), 'EdgeColor', 'b' ) hold on plot ( p(:,1), p(:,2), 'b.' ); axis ( [ -0.0, 1.0, -0.0, 1.0 ] ) line ( [ 0.0, 1.0, 1.0, 0.0, 0.0 ], [ 0.0, 0.0, 1.0, 1.0, 0.0 ], ... 'Color', 'r', 'LineWidth', 2 ); title_string = sprintf ( 'Delaunay, step %d', it ); title ( title_string ); axis equal view ( 2 ) hold off end % Display the CVT generators, and the associated Voronoi diagram. if ( delaunay_display ) subplot ( 1, 2, 1 ) end voronoi ( p(:,1), p(:,2), t ); axis ( [ -0.0, 1.0, -0.0, 1.0 ] ) line ( [ 0.0, 1.0, 1.0, 0.0, 0.0 ], [ 0.0, 0.0, 1.0, 1.0, 0.0 ], ... 'Color', 'r', 'LineWidth', 2 ); title_string = sprintf ( 'Voronoi, step %d', it ); title ( title_string ); axis equal axis tight drawnow % Generate sample points. % % These sample points implicitly define the geometry of the region. % If the region is not a unit square, then the range of the sample % data must be changed. % % The data is sampled uniformly. If a nonuniform density is desired, % then the sampling must be done in a biased way. xs = rand ( sample_num, 1 ); ys = rand ( sample_num, 1 ); k(1:sample_num,1) = dsearch ( p(:,1), p(:,2), t, xs, ys ); % The centroid of the Voronoi region associated with each generator % is approximated by the average of the sample points it was closest to. if ( accumarray_available ) count(1:n) = accumarray ( k, ones(sample_num,1) ); centroid(1,1:n) = accumarray ( k, xs ); centroid(2,1:n) = accumarray ( k, ys ); else count(1:n) = 0; centroid(1,1:n) = 0.0; centroid(2,1:n) = 0.0; for i = 1 : sample_num j = k(i); count(j) = count(j) + 1; centroid(1,j) = centroid(1,j) + xs(i); centroid(2,j) = centroid(2,j) + ys(i); end end % % Replace the generators by the centroids. % p(1:n,1) = ( centroid(1,1:n) ./ count(1:n) )'; p(1:n,2) = ( centroid(2,1:n) ./ count(1:n) )'; string = input ( 'RETURN, or Q to quit: ', 's' ); if ( string == 'q' | string == 'Q' ) break end it = it + 1; end fprintf ( 1, '\n' ); fprintf ( 1, 'CVT_SQUARE_UNIFORM:\n' ); fprintf ( 1, ' Normal end of execution.\n' ); return end function p = square_uniform ( n ) %% SQUARE_UNIFORM returns sample points from the unit square. p(1:n,1:2) = rand(n,2); return end
Bonjour :coucou:
ça, on avait compris. La question était plutôt: "D'où vient le dessin des courbes à l'intérieur des polygones du premier dessin ? Quelle technique a été employée ?"
oui exactement, j'ai essayé plusieurs fonctions( pdepoly-spline................) et ça ne marche plus.
Tu as réussi un dessin mais tu ne sais plus comment ? :fou:
Je cherche à obtenir avec Matlab une structure poreuse dont les pores sont de formes aléatoires.
Dans un document j'ai trouvé cette image qui me semble intéressante, mon problème est de déterminer les formes placées dans les polygones.
A vue de nez ça me semblerait être une courbe de Béziers passant par les milieux des côtés des cellules de Voronoi...
est ce que je peux utiliser ''spline"??