source: trunk/SRC/Interpolation/cutpar.pro

Last change on this file was 495, checked in by pinsard, 10 years ago

fix thanks to coding rules; typo; dupe empty lines; trailing blanks

  • Property svn:keywords set to Id
File size: 2.6 KB
Line 
1;+
2;
3; @file_comments
4; cut p parallelogram(s) into p*n^2 parallelograms
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; @param x2 {in}{required}
14; @param y2 {in}{required}
15; @param x3 {in}{required}
16; @param y3 {in}{required}
17; 1d arrays of p elements, giving the edge positions.
18; The edges must be given as in <proidl>PLOT</proidl> to draw the
19; parallelogram. (see example).
20;
21; @param n {in}{required}
22; each parallelogram will be cut in n^2 pieces
23;
24; @keyword ENDPOINTS
25; see returns
26;
27; @keyword ONSPHERE
28; to specify that the points are located on a
29; sphere. In this case, x and y correspond to longitude and
30; latitude in degrees.
31;
32; @returns
33; by default: a 3d array(2,n^2,p) giving the center position of each
34; piece of the parallelograms
35;
36; if /ENDPOINTS : a 3d array(2,(n+1)^2,p) giving the edge positions
37; of each piece of the parallelograms
38;
39; @uses
40; <pro>cutsegment</pro>
41;
42; @examples
43;
44;   IDL> x0 = [2,6,2]
45;   IDL> y0 = [0,2,6]
46;   IDL> x1 = [3,8,4]
47;   IDL> y1 = [4,4,6]
48;   IDL> x2 = [1,6,4]
49;   IDL> y2 = [5,6,8]
50;   IDL> x3 = [0,4,2]
51;   IDL> y3 = [1,4,8]
52;   IDL> n = 4
53;   IDL> splot, [0,10], [0,10], xstyle = 1, ystyle = 1,/nodata
54;   IDL> 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]]
55;   IDL> res=cutpar(x0, y0, x1, y1, x2, y2, x3, y3, n)
56;   IDL> for i=0,2 do oplot, [res[0,*,i]], [res[1,*,i]], color = 20+10*i, psym = 1, thick = 3
57;
58; @history
59; S. Masson (smasson\@lodyc.jussieu.fr)
60;  - July 5th, 2002
61;
62; @version
63; $Id$
64;
65;-
66FUNCTION cutpar, x0, y0, x1, y1, x2, y2, x3, y3, n $
67               , ENDPOINTS=endpoints, ONSPHERE=onsphere
68;
69  compile_opt idl2, strictarrsubs
70;
71; is it a parallelogram?
72; eps = 1e-4
73; IF total(abs((x0+x2)/2-(x1+x3)/2) GE eps) GT 0 $
74;   OR total(abs((y0+y2)/2-(y1+y3)/2) GE eps) GT 0 $
75;   THEN stop; print, 'NOT a parallelogram'
76; x0(npar)
77  npar = n_elements(x0)
78; firstborder(2,n+keyword_set(endpoints),npar)
79  firstborder = cutsegment(x0, y0, x1, y1, n $
80                           , endpoints = endpoints, onsphere = onsphere)
81  thirdborder = cutsegment(x3, y3, x2, y2, n $
82                           , endpoints = endpoints, onsphere = onsphere)
83; res(2,n+keyword_set(endpoints),(n+keyword_set(endpoints))*npar)
84  res = cutsegment(firstborder[0, *, *], firstborder[1, *, *] $
85                   , thirdborder[0, *, *], thirdborder[1, *, *] $
86                   , n, endpoints = endpoints, onsphere = onsphere)
87; free memory
88  firstborder = -1
89  thirdborder = -1
90; reform the result
91  res = reform(res, 2, (n+keyword_set(endpoints))^2, npar, /overwrite)
92
93  RETURN, res
94END
Note: See TracBrowser for help on using the repository browser.