To illustrate how to display vector data, we begin with a two dimensional vector field that is the gradient of the function , which was used to illustrate contour, raster and surface plots in the previous section. Code 4 illustrates how to write a simple MTV data file containing the vector field (vx,vy,vz) = (2x,-2y,0) on a 25x25 grid over the square 0 < x,y < 5. Note that even though a two dimensional vector field is to be displayed, it is necessary to write the vector data set in the form x y z vx vy vz, where x,y,z specify the tail of a given vector and vx,vy,vz designate the components of the vector.
program vector parameter(mmax=25,nmax=25) parameter(xmin=0.0,ymin=0.0,xmax=5.0,ymax=5.0) parameter(dx=(xmax-xmin)/mmax,dy=(ymax-ymin)/nmax) open(4,file='vect.dat',status='unknown') c Specify that data is to be vectors write(4,*)'$DATA=VECTOR' c Set the maximum and minimum x, y and z-values write(4,*)'%xmin=',xmin write(4,*)'%ymin=',ymin write(4,*)'%xmax=',xmax write(4,*)'%ymax=',ymax write(4,*)'%zmin=-0.5' write(4,*)'%zmax=0.5' c Set a scale factor to control the length of the vectors write(4,*)'%vscale=0.02' z = 0.0 vz = 0.0 y = ymin - dy do 1 n = 1,nmax x = xmin y = y + dy do 2 m = 1,mmax vx = 2.0*x vy = -2.0*y c Write the coordinates of the tail and the components of vector write(4,100)x,y,z,vx,vy,vz x = x + dx 2 continue 1 continue 100 format(3f10.2,' `,3f10.2) close(4) endFigure 6 contains the result of using plotmtv with command line options -pfg WHITE and -pbg NAVY to view the data set produce by Code 4. Figure 6 demonstrates one of the frequently encountered problems one encounters when displaying vector data. Namely, when vectors of markedly different magnitudes are present in the data set, it is difficult to select a scale factor that makes the smallest of the vectors visible, yet prevents the longer vectors from overlapping their neighbors. When this situation is encountered, a number of techniques may help with the visualization of the data.
One technique is to normalize the length of all the vectors to unity and then set the
line color of vectors in proportion to their magnitude. In such a scheme, the arrows
show the flow of the vector field and their colors indicate the "speed" of the flow. A
second technique, when plotting 2D vector fields, is to again normalize the
magnitude of the vectors and use the z component of the tail of the vector to
represent the speed of the flow. Thus, the vectors are displayed as horizontal arrows
on a surface whose height represents the magnitude of the vector. Yet another
technique is to plot the magnitude of the vector field as a contour or color raster map
and then overlay normalized vectors indicating the direction of flow.
Figure 6 Plot of vector field (2x,-2y) from Code 4
The final illustration in this quick start is presented in Figure 7, which was created by combining Codes 2 and 4 to write a file containing two MTV data sets. The first data set contains the raster map of Figure 3, while the second data set contains the vector field of Figure 6. Using the command line syntax
permits the simultaneous display of the two data sets on a single plot. Remember that test1.dat comes from running program cont with contour style = 2, and vect.dat comes from this section's program vector.
Figure 7 Color raster map of x² - y² with the vector field (2x,-2y) superimposed
Previous Section: 3-Space Mapping
Table of Contents (Overview)