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