source: trunk/MESOSCALE/PLOT/MINIMAL/plot_vector.pro @ 205

Last change on this file since 205 was 85, checked in by aslmd, 14 years ago

LMD_MM_MARS et LMD_LES_MARS: ajout des routines IDL pour tracer les sorties --> voir mesoscale/PLOT

  • Property svn:executable set to *
File size: 3.5 KB
Line 
1PRO plot_vector, u, v, x, y, type=type, angle=angle, head_len=head_len,$
2                 maxmag=maxmag, align=align, length=length,$
3                 ref_text=ref_text, color=color, cstyle=cstyle
4;Procedure to calculate and plot a vector
5 
6mylen=300.0 ; length of default arrow in pixels
7rev=1.0   
8x0=0.0
9y0=0.0
10x1=u/maxmag*mylen*length
11y1=v/maxmag*mylen*length
12dx=x1-x0
13IF (dx LT 0.0) THEN rev=-1.0
14dy=y1-y0
15r=SQRT(dx^2+dy^2)
16theta=ATAN(dy/dx)     
17phi=angle*!dtor
18rfrac=head_len
19x2=x1-r*rfrac*rev*COS(theta-phi)
20y2=y1-r*rfrac*rev*SIN(theta-phi)
21x3=x1-r*rfrac*rev*COS(theta+phi)
22y3=y1-r*rfrac*rev*SIN(theta+phi)
23x4=x1-rfrac/2*r*rev*COS(theta)
24y4=y1-rfrac/2*r*rev*SIN(theta)
25;Calculate intersection of vector shaft and head points either
26;side of the shaft - see
27;http://astronomy.swin.edu.au/~pbourke/geometry/lineline2d
28;for more details
29ua=((x3-x2)*(y0-y2)-(y3-y2)*(x0-x2))/$
30   ((y3-y2)*(x1-x0)-(x3-x2)*(y1-y0))
31x5=x0+ua*(x1-x0)
32y5=y0+ua*(y1-y0)
33               
34;Plot vectors in data space - cstyle=0
35;Position in device coordinates and then convert to data coordinates
36IF (cstyle EQ 0) THEN BEGIN
37 pt1=CONVERT_COORD(x,y, /DATA, /TO_DEVICE)
38 xpts=[x0,x1,x2,x3,x4,x5]+pt1[0]-align*dx
39 ypts=[y0,y1,y2,y3,y4,y5]+pt1[1]-align*dy
40 pts=CONVERT_COORD(xpts,ypts, /DEVICE, /TO_DATA)
41 xpts=pts[0,*]
42 ypts=pts[1,*]
43 x0=xpts[0]
44 x1=xpts[1]
45 x2=xpts[2]
46 x3=xpts[3]
47 x4=xpts[4]
48 x5=xpts[5]
49 y0=ypts[0]
50 y1=ypts[1]
51 y2=ypts[2]
52 y3=ypts[3]
53 y4=ypts[4]
54 y5=ypts[5]   
55   
56               
57; Plot the vectors omiting any vectors with NaNs
58 z=[xpts, ypts]         
59 IF (TOTAL(FINITE(z)) EQ 12) THEN BEGIN
60  IF (N_ELEMENTS(TYPE) EQ 0) THEN TYPE=0
61  IF (TYPE EQ 0) THEN BEGIN     
62    PLOTS, [x0,x1,x2,x1,x3], [y0,y1,y2,y1,y3], COLOR=color
63  ENDIF
64  IF (TYPE EQ 1) THEN BEGIN     
65    PLOTS, [x0,x5,x3,x1,x2,x5], [y0,y5,y3,y1,y2,y5], COLOR=color
66  ENDIF 
67  IF (TYPE EQ 2) THEN BEGIN     
68    PLOTS, [x0,x4,x2,x1,x3,x4], [y0,y4,y2,y1,y3,y4], COLOR=color
69  ENDIF
70  IF (TYPE EQ 3) THEN BEGIN     
71    PLOTS, [x0,x1], [y0,y1], COLOR=color
72    POLYFILL, [x1,x2,x3,x1], [y1,y2,y3,y1], COLOR=color
73  ENDIF
74  IF (TYPE EQ 4) THEN BEGIN     
75    PLOTS, [x0,x4], [y0,y4], COLOR=color
76   POLYFILL, [x1,x2,x4,x3,x1], [y1,y2,y4,y3,y1], COLOR=color
77  ENDIF
78 ENDIF
79ENDIF   
80
81
82;Plot reference vector - cstyle=1
83;Position in device coordinates and then convert to data coordinates
84IF (cstyle EQ 1) THEN BEGIN
85 pt1=CONVERT_COORD(x,y, /NORMAL, /TO_DEVICE)
86 xpts=[x0,x1,x2,x3,x4,x5]+pt1[0]
87 ypts=[y0,y1,y2,y3,y4,y5]+pt1[1]
88 x0=xpts[0]
89 x1=xpts[1]
90 x2=xpts[2]
91 x3=xpts[3]
92 x4=xpts[4]
93 x5=xpts[5]
94 y0=ypts[0]
95 y1=ypts[1]
96 y2=ypts[2]
97 y3=ypts[3]
98 y4=ypts[4]
99 y5=ypts[5]     
100               
101; Plot the vectors omiting any vectors with NaNs
102 z=[xpts, ypts]         
103 IF (TOTAL(FINITE(z)) EQ 12) THEN BEGIN
104  IF (N_ELEMENTS(TYPE) EQ 0) THEN TYPE=0
105  IF (TYPE EQ 0) THEN BEGIN     
106    PLOTS, [x0,x1,x2,x1,x3], [y0,y1,y2,y1,y3], COLOR=color, /DEVICE
107  ENDIF
108  IF (TYPE EQ 1) THEN BEGIN     
109    PLOTS, [x0,x5,x3,x1,x2,x5], [y0,y5,y3,y1,y2,y5], COLOR=color, /DEVICE
110  ENDIF 
111  IF (TYPE EQ 2) THEN BEGIN     
112    PLOTS, [x0,x4,x2,x1,x3,x4], [y0,y4,y2,y1,y3,y4], COLOR=color, /DEVICE
113  ENDIF
114  IF (TYPE EQ 3) THEN BEGIN     
115    PLOTS, [x0,x1], [y0,y1], COLOR=color, /DEVICE
116    POLYFILL, [x1,x2,x3,x1], [y1,y2,y3,y1], COLOR=color, /DEVICE
117  ENDIF
118  IF (TYPE EQ 4) THEN BEGIN     
119    PLOTS, [x0,x4], [y0,y4], COLOR=color, /DEVICE
120   POLYFILL, [x1,x2,x4,x3,x1], [y1,y2,y4,y3,y1], COLOR=color, /DEVICE
121  ENDIF
122 ENDIF
123 
124 ;Add the reference vector text
125 IF (N_ELEMENTS(REF_TEXT) EQ 0) THEN ref_text=' '
126 XYOUTS, x0-100, y0-100, ref_text, ALIGNMENT=1.0, /DEVICE
127ENDIF
128       
129END             
Note: See TracBrowser for help on using the repository browser.