[59] | 1 | ;+ |
---|
| 2 | ; |
---|
[101] | 3 | ; @file_comments cut p parallelogram(s) into p*n^2 parallelograms |
---|
[59] | 4 | ; |
---|
[101] | 5 | ; @categories basic work |
---|
[59] | 6 | ; |
---|
[101] | 7 | ; @examples |
---|
| 8 | ; res = cutpar(x0, y0, x1, y1, x2, y2, x3, y3, n) |
---|
[59] | 9 | ; |
---|
[101] | 10 | ; @param x0,y0 {in}{required} 1d arrays of p elements, giving the edge positions. The |
---|
[59] | 11 | ; edges must be given as in plot to traw the parallelogram. (see |
---|
| 12 | ; example). |
---|
[101] | 13 | ; @param n {in}{required} each parallelogram will be cutted in n^2 pieces |
---|
[59] | 14 | ; |
---|
[101] | 15 | ; @keyword /endpoints see outputs |
---|
[59] | 16 | ; |
---|
[101] | 17 | ; @keyword /onsphere to specify that the points are located on a |
---|
[59] | 18 | ; sphere. In this case, x and y corresponds to longitude and |
---|
| 19 | ; latitude in degrees. |
---|
| 20 | ; |
---|
[101] | 21 | ; @returns |
---|
[59] | 22 | ; -defaut: 3d array(2,n^2,p) giving the center position of each |
---|
| 23 | ; piece of the parallelograms |
---|
| 24 | ; -/endpoints: 3d array(2,(n+1)^2,p) giving the edge positions |
---|
| 25 | ; of each piece of the parallelograms |
---|
| 26 | ; |
---|
[101] | 27 | ; @uses cutsegment.pro |
---|
[59] | 28 | ; |
---|
[101] | 29 | ; @examples |
---|
[59] | 30 | ; |
---|
| 31 | ; x0 = [2,6,2] |
---|
| 32 | ; y0 = [0,2,6] |
---|
| 33 | ; x1 = [3,8,4] |
---|
| 34 | ; y1 = [4,4,6] |
---|
| 35 | ; x2 = [1,6,4] |
---|
| 36 | ; y2 = [5,6,8] |
---|
| 37 | ; x3 = [0,4,2] |
---|
| 38 | ; y3 = [1,4,8] |
---|
| 39 | ; n = 4 |
---|
| 40 | ; splot, [0,10], [0,10], xstyle = 1, ystyle = 1,/nodata |
---|
| 41 | ; for i=0,2 do oplot, [x0[i],x1[i],x2[i],x3[i],x0[i]],[y0[i],y1[i],y2[i],y3[i],y0[i]] |
---|
| 42 | ; res=cutpar(x0, y0, x1, y1, x2, y2, x3, y3, n) |
---|
| 43 | ; for i=0,2 do oplot, [res[0,*,i]], [res[1,*,i]], color = 20+10*i, psym = 1, thick = 3 |
---|
| 44 | ; |
---|
[101] | 45 | ; @history |
---|
| 46 | ; S. Masson (smasson\@lodyc.jussieu.fr) |
---|
[59] | 47 | ; July 5th, 2002 |
---|
| 48 | ;- |
---|
| 49 | FUNCTION cutpar, x0, y0, x1, y1, x2, y2, x3, y3, n, endpoints = endpoints, onsphere = onsphere |
---|
| 50 | ; is it a parallelogram? |
---|
| 51 | ; eps = 1e-4 |
---|
| 52 | ; IF total(abs((x0+x2)/2-(x1+x3)/2) GE eps) GT 0 $ |
---|
| 53 | ; OR total(abs((y0+y2)/2-(y1+y3)/2) GE eps) GT 0 $ |
---|
| 54 | ; THEN stop; print, 'NOT a parallelogram' |
---|
| 55 | ; x0(npar) |
---|
| 56 | npar = n_elements(x0) |
---|
| 57 | ; firstborder(2,n+keyword_set(endpoints),npar) |
---|
| 58 | firstborder = cutsegment(x0, y0, x1, y1, n $ |
---|
| 59 | , endpoints = endpoints, onsphere = onsphere) |
---|
| 60 | thirdborder = cutsegment(x3, y3, x2, y2, n $ |
---|
| 61 | , endpoints = endpoints, onsphere = onsphere) |
---|
| 62 | ; res(2,n+keyword_set(endpoints),(n+keyword_set(endpoints))*npar) |
---|
| 63 | res = cutsegment(firstborder[0, *, *], firstborder[1, *, *] $ |
---|
| 64 | , thirdborder[0, *, *], thirdborder[1, *, *] $ |
---|
| 65 | , n, endpoints = endpoints, onsphere = onsphere) |
---|
| 66 | ; free memory |
---|
| 67 | firstborder = -1 |
---|
| 68 | thirdborder = -1 |
---|
| 69 | ; reform the result |
---|
| 70 | res = reform(res, 2, (n+keyword_set(endpoints))^2, npar, /overwrite) |
---|
| 71 | |
---|
| 72 | RETURN, res |
---|
| 73 | END |
---|