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
RevLine 
[2]1;+
2;
[150]3; @file_comments
[232]4; Define a triangulation array like <proidl>TRIANGULATE</proidl>.
[2]5;         But in a VERY SIMPLE CASE:
[297]6; the points are regularly-gridded on nx*ny array.
[2]7; Find a Delaunay triangulation for this set of points is easy:
[231]8; Points define (nx-1)*(ny-1) rectangles which we can cut in 2 triangles.
[186]9; cf. figure above
[2]10;
[157]11; <fixe>
[186]12; fixe
[2]13;      ny-1*---*---*. . . . . .*---*---*
[231]14;          |  +|  +|           |  +|  +|
[157]15;          | + | + |           | + | + |
16;          |+  |+  |           |+  |+  |
[231]17;      ny-2*---*---*. . . . . .*---*---*
[2]18;          .       .           .       .
19;          .       .           .       .
20;          .       .           .       .
21;         1*---*---*. . . . . .*---*---*
[163]22;          |  +|  +|           |  +|  +|
23;          | + | + |           | + | + |
24;          |+  |+  |           |+  |+  |
[231]25;         0*---*---*. . . . . .*---*---*
[157]26;           0   1   2        nx-3  nx-2 nx-1
27; </fixe>
[2]28;
29;  You have 2 ways to cut a rectangle:
30;      1) the upward diagonal       2) the downward diagonal
31;
[157]32; <fixe>
[2]33;          *---*                        *---*
[157]34;          |  +|                        |+  |
35;          | + |                        | + |
36;          |+  |                        |  +|
[231]37;          *---*                        *---*
[157]38; </fixe>
[2]39;
[150]40; @categories
[157]41; Utilities
[231]42;
[150]43; @param NX {in}{required}
44; The x dimension array
[2]45;
[150]46; @param NY {in}{required}
47; The y dimension array
[2]48;
[150]49; @param DOWNWARD {in}{optional}
[231]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
[186]53; using the downward diagonal.
[231]54; The rectangle number is defined by the index (in a nx*ny vector) of the
[186]55; lower-left corner of the rectangle.
[2]56;
[150]57; @returns
[186]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.
[2]60;
[150]61; @examples
[2]62;
[186]63; IDL> triangles=definetri(3,3,[1,3])
64; triangles will be this kind of triangulation:
[2]65;
66;          *---*---*
[186]67;          |+  |  +|
68;          | + | + |
69;          |  +|+  |
[2]70;          *---*---*
[186]71;          |  +|+  |
72;          | + | + |
73;          |+  |  +|
[2]74;          *---*---*
75;
76;
[150]77; @history
[157]78; sebastien Masson (smlod\@ipsl.jussieu.fr)
[2]79;                       4/3/1999
80;
[150]81; @version
82; $Id$
[2]83;-
[262]84;
[2]85FUNCTION definetri, nx, ny, downward
[114]86;
87  compile_opt idl2, strictarrsubs
88;
[2]89   nx = long(nx)
90   ny = long(ny)
[231]91   if n_elements(downward) NE 0 THEN BEGIN
[2]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
[231]98; we define triangles
[2]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.
[186]106; The rectangle number is defined by the index (in a nx*ny vector) of
[2]107; the lower-left corner of the rectangle.
108      upward = bytarr(nx, ny)+1
[114]109      upward[*, ny-1] = 0
110      upward[nx-1, *] = 0
[2]111      if n_elements(downward) NE 0 then upward[downward] = 0
112      upward = where(upward EQ 1)
[231]113      n1 = n_elements(upward)
[2]114;
115; 4 corners indexes of a rectangle number i are
116;
117;       i+nx  i+nx+1
[231]118;          *---*
119;          |  +|
120;          | + |
121;          |+  |
122;          *---*
[2]123;          i   i+1
124;
125      trinumber = 2*(upward-upward/nx)
[297]126; we define the right triangles
[2]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
[231]139      n2 = n_elements(downward)
[2]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.