[59] | 1 | ;+ |
---|
| 2 | ; |
---|
[101] | 3 | ; @file_comments cut p segments into p*n equal parts |
---|
[59] | 4 | ; |
---|
[101] | 5 | ; @categories basic work |
---|
[59] | 6 | ; |
---|
[101] | 7 | ; @examples |
---|
| 8 | ; res = cutsegment(x0, y0, x1, y1, n) |
---|
[59] | 9 | ; |
---|
[101] | 10 | ; @param x0,y0 and x1,y1 {in}{required} 1d arrays of p elements, the coordinates of |
---|
[59] | 11 | ; the endpoints of the p segmements |
---|
[101] | 12 | ; @param n {in}{required} the number of pieces we want to cut each segment |
---|
[59] | 13 | ; |
---|
| 14 | ; |
---|
[101] | 15 | ; @keyword /endpoints see ouputs |
---|
[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: a 3d array (2,n,p) that gives the coordinates of the |
---|
| 23 | ; middle of the cutted segments. |
---|
| 24 | ; if /endpoints, a 3d array (2,n+1,p) that gives the |
---|
| 25 | ; coordinates of the endpoints of the cutted segments. |
---|
| 26 | ; |
---|
[101] | 27 | ; @examples |
---|
[59] | 28 | ; |
---|
| 29 | ; IDL> x0=[2,5] |
---|
| 30 | ; IDL> y0=[5,1] |
---|
| 31 | ; IDL> x1=[9,3] |
---|
| 32 | ; IDL> y1=[1,8] |
---|
| 33 | ; IDL> res=cutsegment(x0, y0, x1, y1, 10) |
---|
| 34 | ; IDL> splot, [0,10], [0,10], xstyle = 1, ystyle = 1,/nodata |
---|
| 35 | ; IDL> oplot, [x0[0], x1[0]], [y0[0], y1[0]] |
---|
| 36 | ; IDL> oplot, [res[0,*,0]], [res[1,*,0]], color = 20, psym = 1, thick = 3 |
---|
| 37 | ; IDL> oplot, [x0[1], x1[1]], [y0[1], y1[1]] |
---|
| 38 | ; IDL> oplot, [res[0,*,1]], [res[1,*,1]], color = 40, psym = 1, thick = 3 |
---|
| 39 | ; |
---|
[101] | 40 | ; @history |
---|
| 41 | ; S. Masson (smasson\@lodyc.jussieu.fr) |
---|
[59] | 42 | ; July 5th, 2002 |
---|
| 43 | ;- |
---|
| 44 | FUNCTION cutsegment, x0, y0, x1, y1, n, endpoints = endpoints, onsphere = onsphere |
---|
[114] | 45 | ; |
---|
| 46 | compile_opt idl2, strictarrsubs |
---|
| 47 | ; |
---|
[59] | 48 | ; number of segment |
---|
| 49 | nseg = n_elements(x0) |
---|
| 50 | ; number of point to find on each segment |
---|
| 51 | n2find = n+keyword_set(endpoints) |
---|
| 52 | ; |
---|
| 53 | IF keyword_set(onsphere) THEN BEGIN |
---|
| 54 | ; save the inputs arrays |
---|
| 55 | x0in = temporary(x0) |
---|
| 56 | y0in = temporary(y0) |
---|
| 57 | x1in = temporary(x1) |
---|
| 58 | y1in = temporary(y1) |
---|
| 59 | sp_cood = [transpose(x0in[*]),transpose(y0in[*]),replicate(1, 1, nseg)] |
---|
| 60 | rect_coord = CV_COORD(FROM_SPHERE = temporary(sp_cood), /TO_RECT, /DEGREES) |
---|
| 61 | x0 = rect_coord[0, *] |
---|
| 62 | y0 = rect_coord[1, *] |
---|
| 63 | z0 = rect_coord[2, *] |
---|
| 64 | rect_coord = -1 ;free memory |
---|
| 65 | sp_cood = [transpose(x1in[*]),transpose(y1in[*]),replicate(1, 1, nseg)] |
---|
| 66 | rect_coord = CV_COORD(FROM_SPHERE = temporary(sp_cood), /TO_RECT, /DEGREES) |
---|
| 67 | x1 = rect_coord[0, *] |
---|
| 68 | y1 = rect_coord[1, *] |
---|
| 69 | z1 = rect_coord[2, *] |
---|
| 70 | rect_coord = -1 ;free memory |
---|
| 71 | ENDIF |
---|
| 72 | ; |
---|
| 73 | resx = replicate(1, n2find)#x0[*] |
---|
| 74 | resx = temporary(resx)+(1./n*(findgen(n2find) $ |
---|
| 75 | +.5*(1-keyword_set(endpoints))))#(x1-x0)[*] |
---|
| 76 | resx = (temporary(resx))[*] |
---|
| 77 | ; |
---|
| 78 | resy = replicate(1, n2find)#y0[*] |
---|
| 79 | resy = temporary(resy)+(1./n*(findgen(n2find) $ |
---|
| 80 | +.5*(1-keyword_set(endpoints))))#(y1-y0)[*] |
---|
| 81 | resy = (temporary(resy))[*] |
---|
| 82 | |
---|
| 83 | IF keyword_set(onsphere) THEN BEGIN |
---|
| 84 | resz = replicate(1, n2find)#z0[*] |
---|
| 85 | resz = temporary(resz)+(1./n*(findgen(n2find) $ |
---|
| 86 | +.5*(1-keyword_set(endpoints))))#(z1-z0)[*] |
---|
| 87 | resz = (temporary(resz))[*] |
---|
| 88 | |
---|
| 89 | rec_cood = [transpose(temporary(resx)), transpose(temporary(resy)) $ |
---|
| 90 | , transpose(temporary(resz))] |
---|
| 91 | res = CV_COORD(FROM_RECT = temporary(rec_cood), /TO_SPHERE, /DEGREES) |
---|
| 92 | ; restore the input arrays |
---|
| 93 | x0 = temporary(x0in) |
---|
| 94 | y0 = temporary(y0in) |
---|
| 95 | x1 = temporary(x1in) |
---|
| 96 | y1 = temporary(y1in) |
---|
| 97 | ENDIF ELSE res = [transpose(temporary(resx)), transpose(temporary(resy))] |
---|
| 98 | |
---|
| 99 | res = reform(res[0:1, *], 2, n2find, nseg, /overwrite) |
---|
| 100 | |
---|
| 101 | RETURN, res |
---|
| 102 | END |
---|