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

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

improvements/corrections of some *.pro headers

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 4.7 KB
Line 
1;+
2;
3; @file_comments
4; Define a triangulation array like TRIANGULATE.
5;         But in a VERY SIMPLE CASE:
6; the points are regulary-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;-
84FUNCTION definetri, nx, ny, downward
85;
86  compile_opt idl2, strictarrsubs
87;
88   nx = long(nx)
89   ny = long(ny)
90   if n_elements(downward) NE 0 THEN BEGIN
91      if n_elements(downward) GT (nx-1)*(ny-1) then begin
92         print, 'downward a trop d''elements par rapport a nx et ny!'
93         return,  -1
94      endif
95      downward = long(downward)
96   ENDIF
97; we define triangles
98   triangles = lonarr(3, 2*(nx-1)*(ny-1))
99;----------------------------------------------------------------------------------
100; we cut the rectangles with the upward diagonal
101;----------------------------------------------------------------------------------
102   if n_elements(downward) NE (nx-1)*(ny-1) then BEGIN ; there is some rectangle to cut.
103; we define upward: upward is a vector which contains the rectangles
104; numbers which are cut in using the upward diagonal.
105; The rectangle number is defined by the index (in a nx*ny vector) of
106; the lower-left corner of the rectangle.
107      upward = bytarr(nx, ny)+1
108      upward[*, ny-1] = 0
109      upward[nx-1, *] = 0
110      if n_elements(downward) NE 0 then upward[downward] = 0
111      upward = where(upward EQ 1)
112      n1 = n_elements(upward)
113;
114; 4 corners indexes of a rectangle number i are
115;
116;       i+nx  i+nx+1
117;          *---*                   
118;          |  +|                   
119;          | + |                   
120;          |+  |                 
121;          *---*               
122;          i   i+1
123;
124      trinumber = 2*(upward-upward/nx)
125;; we define the right triangles
126      triangles[0, trinumber] = upward
127      triangles[1, trinumber] = upward+1
128      triangles[2, trinumber] = upward+1+nx
129; we define the left triangles
130      triangles[0, trinumber+1] = upward+1+nx
131      triangles[1, trinumber+1] = upward+nx
132      triangles[2, trinumber+1] = upward
133   ENDIF ELSE n1 = 0
134;----------------------------------------------------------------------------------
135; we cut the rectangles with the downward diagonal
136;----------------------------------------------------------------------------------
137   if n_elements(downward) NE 0 then BEGIN
138      n2 = n_elements(downward)
139      trinumber = 2*(downward-downward/nx)
140; we define the right triangles
141      triangles[0, trinumber] = downward+1
142      triangles[1, trinumber] = downward+nx+1
143      triangles[2, trinumber] = downward+nx
144; we define the left triangles
145      triangles[0, trinumber+1] = downward+nx
146      triangles[1, trinumber+1] = downward
147      triangles[2, trinumber+1] = downward+1
148   endif
149
150   return, triangles
151end
Note: See TracBrowser for help on using the repository browser.