source: trunk/TRIANGULATION/definetri.pro @ 2

Last change on this file since 2 was 2, checked in by opalod, 22 years ago

Initial revision

  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 4.9 KB
Line 
1;+
2; NAME:definetri
3;
4; PURPOSE: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
9; triangles. cf. figure above
10;
11;
12;      ny-1*---*---*. . . . . .*---*---*
13;          |  /|  /|           |  /|  /|     
14;          | / | / |           | / | / |
15;          |/  |/  |           |/  |/  |
16;      ny-2*---*---*. . . . . .*---*---*   
17;          .       .           .       .
18;          .       .           .       .
19;          .       .           .       .
20;         1*---*---*. . . . . .*---*---*
21;          |  /|  /|           |  /|  /|
22;          | / | / |           | / | / |
23;          |/  |/  |           |/  |/  |
24;         0*---*---*. . . . . .*---*---* 
25;          0   1   2        nx-3  nx-2 nx-1
26;
27;  You have 2 ways to cut a rectangle:
28;      1) the upward diagonal       2) the downward diagonal
29;
30;          *---*                        *---*
31;          |  /|                        |\  |
32;          | / |                        | \ |
33;          |/  |                        |  \|
34;          *---*                        *---* 
35;
36;
37; CATEGORY: to understand how TRIANGULATE and TRIANGULATION work!
38;
39; CALLING SEQUENCE:triangles=definetri(nx, ny [,downward])
40;
41; INPUTS: nx and ny are the array dimensions
42;
43; OPTIONAL INPUTS:
44;
45;        downward: When downward is undefine all rectangles are cut
46;        in using the upward diagonal. Downward is a vector which
47;        contains the rectangles numbers which are cut in using the
48;        downward diagonal.
49;        The rectangle number is define by the index (in a nx*ny
50;        vector) of the lower-left corner of the rectangle.
51;
52; KEYWORD PARAMETERS:
53;
54; OUTPUTS:
55;        triangles is a 2d array and is dimensions are 3 and
56;        2*(nx-1)*(ny-1)
57;        triangles is define like in the TRIANGULATE procedure.
58;       
59;
60; OPTIONAL OUTPUTS:
61;
62; COMMON BLOCKS:
63;
64; SIDE EFFECTS:
65;
66; RESTRICTIONS:
67;
68; PROCEDURE:
69;
70; EXAMPLE:
71;
72; triangles=definetri(3,3,[1,3])
73; triangles will be a this kind of triangulation:
74;
75;          *---*---*
76;          |\  |  /|
77;          | \ | / |
78;          |  \|/  |
79;          *---*---*
80;          |  /|\  |
81;          | / | \ |
82;          |/  |  \|
83;          *---*---*
84;
85;
86; MODIFICATION HISTORY: sebastien Masson (smlod@ipsl.jussieu.fr)
87;                       4/3/1999
88;
89;-
90FUNCTION definetri, nx, ny, downward
91   nx = long(nx)
92   ny = long(ny)
93   if n_elements(downward) NE 0 THEN BEGIN
94      if n_elements(downward) GT (nx-1)*(ny-1) then begin
95         print, 'downward a trop d''elements par rapport a nx et ny!'
96         return,  -1
97      endif
98      downward = long(downward)
99   ENDIF
100; we define triangles
101   triangles = lonarr(3, 2*(nx-1)*(ny-1))
102;----------------------------------------------------------------------------------
103; we cut the rectangles with the upward diagonal
104;----------------------------------------------------------------------------------
105   if n_elements(downward) NE (nx-1)*(ny-1) then BEGIN ; there is some rectangle to cut.
106; we define upward: upward is a vector which contains the rectangles
107; numbers which are cut in using the upward diagonal.
108; The rectangle number is define by the index (in a nx*ny vector) of
109; the lower-left corner of the rectangle.
110      upward = bytarr(nx, ny)+1
111      upward(*, ny-1) = 0
112      upward(nx-1, *) = 0
113      if n_elements(downward) NE 0 then upward[downward] = 0
114      upward = where(upward EQ 1)
115      n1 = n_elements(upward)
116;
117; 4 corners indexes of a rectangle number i are
118;
119;       i+nx  i+nx+1
120;          *---*                   
121;          |  /|                   
122;          | / |                   
123;          |/  |                 
124;          *---*               
125;          i   i+1
126;
127      trinumber = 2*(upward-upward/nx)
128;; we define the right triangles
129      triangles[0, trinumber] = upward
130      triangles[1, trinumber] = upward+1
131      triangles[2, trinumber] = upward+1+nx
132; we define the left triangles
133      triangles[0, trinumber+1] = upward+1+nx
134      triangles[1, trinumber+1] = upward+nx
135      triangles[2, trinumber+1] = upward
136   ENDIF ELSE n1 = 0
137;----------------------------------------------------------------------------------
138; we cut the rectangles with the downward diagonal
139;----------------------------------------------------------------------------------
140   if n_elements(downward) NE 0 then BEGIN
141      n2 = n_elements(downward)
142      trinumber = 2*(downward-downward/nx)
143; we define the right triangles
144      triangles[0, trinumber] = downward+1
145      triangles[1, trinumber] = downward+nx+1
146      triangles[2, trinumber] = downward+nx
147; we define the left triangles
148      triangles[0, trinumber+1] = downward+nx
149      triangles[1, trinumber+1] = downward
150      triangles[2, trinumber+1] = downward+1
151   endif
152
153   return, triangles
154end
Note: See TracBrowser for help on using the repository browser.