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