source: trunk/SRC/Interpolation/cutsegment.pro @ 134

Last change on this file since 134 was 134, checked in by navarro, 18 years ago

change *.pro file properties (del eof-style, del executable, set keywords Id

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