source: trunk/SRC/ToBeReviewed/TRIANGULATION/definetri.pro @ 297

Last change on this file since 297 was 297, checked in by pinsard, 17 years ago

typo

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 4.6 KB
Line 
1;+
2;
3; @file_comments
4; Define a triangulation array like <proidl>TRIANGULATE</proidl>.
5;         But in a VERY SIMPLE CASE:
6; the points are regularly-gridded on nx*ny array.
7; Find a Delaunay triangulation for this set of points is easy:
8; Points define (nx-1)*(ny-1) rectangles which we can cut in 2 triangles.
9; cf. figure above
10;
11; <fixe>
12; fixe
13;      ny-1*---*---*. . . . . .*---*---*
14;          |  +|  +|           |  +|  +|
15;          | + | + |           | + | + |
16;          |+  |+  |           |+  |+  |
17;      ny-2*---*---*. . . . . .*---*---*
18;          .       .           .       .
19;          .       .           .       .
20;          .       .           .       .
21;         1*---*---*. . . . . .*---*---*
22;          |  +|  +|           |  +|  +|
23;          | + | + |           | + | + |
24;          |+  |+  |           |+  |+  |
25;         0*---*---*. . . . . .*---*---*
26;           0   1   2        nx-3  nx-2 nx-1
27; </fixe>
28;
29;  You have 2 ways to cut a rectangle:
30;      1) the upward diagonal       2) the downward diagonal
31;
32; <fixe>
33;          *---*                        *---*
34;          |  +|                        |+  |
35;          | + |                        | + |
36;          |+  |                        |  +|
37;          *---*                        *---*
38; </fixe>
39;
40; @categories
41; Utilities
42;
43; @param NX {in}{required}
44; The x dimension array
45;
46; @param NY {in}{required}
47; The y dimension array
48;
49; @param DOWNWARD {in}{optional}
50; When DOWNWARD is undefined all rectangles are cut in using the upward
51; diagonal.
52; DOWNWARD is a vector which contains the rectangles numbers which are cut in
53; using the downward diagonal.
54; The rectangle number is defined by the index (in a nx*ny vector) of the
55; lower-left corner of the rectangle.
56;
57; @returns
58; triangles is a 2d array and its dimensions are 3 and 2*(nx-1)*(ny-1).
59; triangles is defined like in the TRIANGULATE procedure.
60;
61; @examples
62;
63; IDL> triangles=definetri(3,3,[1,3])
64; triangles will be this kind of triangulation:
65;
66;          *---*---*
67;          |+  |  +|
68;          | + | + |
69;          |  +|+  |
70;          *---*---*
71;          |  +|+  |
72;          | + | + |
73;          |+  |  +|
74;          *---*---*
75;
76;
77; @history
78; sebastien Masson (smlod\@ipsl.jussieu.fr)
79;                       4/3/1999
80;
81; @version
82; $Id$
83;-
84;
85FUNCTION definetri, nx, ny, downward
86;
87  compile_opt idl2, strictarrsubs
88;
89   nx = long(nx)
90   ny = long(ny)
91   if n_elements(downward) NE 0 THEN BEGIN
92      if n_elements(downward) GT (nx-1)*(ny-1) then begin
93         print, 'downward a trop d''elements par rapport a nx et ny!'
94         return,  -1
95      endif
96      downward = long(downward)
97   ENDIF
98; we define triangles
99   triangles = lonarr(3, 2*(nx-1)*(ny-1))
100;----------------------------------------------------------------------------------
101; we cut the rectangles with the upward diagonal
102;----------------------------------------------------------------------------------
103   if n_elements(downward) NE (nx-1)*(ny-1) then BEGIN ; there is some rectangle to cut.
104; we define upward: upward is a vector which contains the rectangles
105; numbers which are cut in using the upward diagonal.
106; The rectangle number is defined by the index (in a nx*ny vector) of
107; the lower-left corner of the rectangle.
108      upward = bytarr(nx, ny)+1
109      upward[*, ny-1] = 0
110      upward[nx-1, *] = 0
111      if n_elements(downward) NE 0 then upward[downward] = 0
112      upward = where(upward EQ 1)
113      n1 = n_elements(upward)
114;
115; 4 corners indexes of a rectangle number i are
116;
117;       i+nx  i+nx+1
118;          *---*
119;          |  +|
120;          | + |
121;          |+  |
122;          *---*
123;          i   i+1
124;
125      trinumber = 2*(upward-upward/nx)
126; we define the right triangles
127      triangles[0, trinumber] = upward
128      triangles[1, trinumber] = upward+1
129      triangles[2, trinumber] = upward+1+nx
130; we define the left triangles
131      triangles[0, trinumber+1] = upward+1+nx
132      triangles[1, trinumber+1] = upward+nx
133      triangles[2, trinumber+1] = upward
134   ENDIF ELSE n1 = 0
135;----------------------------------------------------------------------------------
136; we cut the rectangles with the downward diagonal
137;----------------------------------------------------------------------------------
138   if n_elements(downward) NE 0 then BEGIN
139      n2 = n_elements(downward)
140      trinumber = 2*(downward-downward/nx)
141; we define the right triangles
142      triangles[0, trinumber] = downward+1
143      triangles[1, trinumber] = downward+nx+1
144      triangles[2, trinumber] = downward+nx
145; we define the left triangles
146      triangles[0, trinumber+1] = downward+nx
147      triangles[1, trinumber+1] = downward
148      triangles[2, trinumber+1] = downward+1
149   endif
150
151   return, triangles
152end
Note: See TracBrowser for help on using the repository browser.