[2] | 1 | ;+ |
---|
| 2 | ; |
---|
[150] | 3 | ; @file_comments |
---|
[157] | 4 | ; Define a triangulation array like TRIANGULATE. |
---|
[2] | 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: |
---|
[186] | 8 | ; Points define (nx-1)*(ny-1) rectangles which we can cut in 2 triangles. |
---|
| 9 | ; cf. figure above |
---|
[2] | 10 | ; |
---|
[157] | 11 | ; <fixe> |
---|
[186] | 12 | ; fixe |
---|
[2] | 13 | ; ny-1*---*---*. . . . . .*---*---* |
---|
[157] | 14 | ; | +| +| | +| +| |
---|
| 15 | ; | + | + | | + | + | |
---|
| 16 | ; |+ |+ | |+ |+ | |
---|
[2] | 17 | ; ny-2*---*---*. . . . . .*---*---* |
---|
| 18 | ; . . . . |
---|
| 19 | ; . . . . |
---|
| 20 | ; . . . . |
---|
| 21 | ; 1*---*---*. . . . . .*---*---* |
---|
[163] | 22 | ; | +| +| | +| +| |
---|
| 23 | ; | + | + | | + | + | |
---|
| 24 | ; |+ |+ | |+ |+ | |
---|
[2] | 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 | ; |+ | | +| |
---|
[2] | 37 | ; *---* *---* |
---|
[157] | 38 | ; </fixe> |
---|
[2] | 39 | ; |
---|
[150] | 40 | ; @categories |
---|
[157] | 41 | ; Utilities |
---|
[2] | 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} |
---|
[186] | 50 | ; When downward is undefine 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. |
---|
[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 | ;- |
---|
| 84 | FUNCTION definetri, nx, ny, downward |
---|
[114] | 85 | ; |
---|
| 86 | compile_opt idl2, strictarrsubs |
---|
| 87 | ; |
---|
[2] | 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. |
---|
[186] | 105 | ; The rectangle number is defined by the index (in a nx*ny vector) of |
---|
[2] | 106 | ; the lower-left corner of the rectangle. |
---|
| 107 | upward = bytarr(nx, ny)+1 |
---|
[114] | 108 | upward[*, ny-1] = 0 |
---|
| 109 | upward[nx-1, *] = 0 |
---|
[2] | 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 | ; *---* |
---|
[157] | 118 | ; | +| |
---|
| 119 | ; | + | |
---|
| 120 | ; |+ | |
---|
[2] | 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 |
---|
| 151 | end |
---|