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

Last change on this file was 371, checked in by pinsard, 16 years ago

improvements of headers (alignments of IDL prompt in examples)

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