(* This application is copywrite of the Thirring Institute for Applied Gravitational Research, feel free to make any modifications you feel neccessary, I ask only that you mention the Institute's name in anything you use this with *) BeginPackage["Graphics`VectorPlot`"] VectorPlot::usage="VectorPlot[{x,y},{x,xmin,xmax},{y,ymin,ymax}] Plots the 2-D vector field streamlines given by the field {x,y}" VectorPlot3D::usage="VectorPlot3D[{x,y,z},{x,xmin,xmax},{y,ymin,ymax}, {z,zmin,zmax}] Plots the 3D vector field streamlines given by the field {x,y,z}" Begin["`Private`"] (* Sets up 2D vector element as a line with length i to be determined later *) Vector[r_List,v_List,i_]:=Block[{l},l=v[[1]]+1. I v[[2]];Line[{r,r+i*{Cos[Arg[l]], Sin[Arg[l]]}}]] (* creates an array of vectors to be called on by the VectorPlot function *) FieldTable[v_List,{x_,xmin_,xmax_},{y_,ymin_,ymax_}]:=Block[{l} ,l=Sqrt[(xmax-xmin)^2+(ymax-ymin)^2];Table[{Point[{x,y}],Vector[{x,y} , v,l/40]},{x,xmin,xmax,(xmax-xmin)/20},{y,ymin,ymax,(ymax-ymin)/20}]] VectorPlot[{a_,b_},{c_,cmin_,cmax_},{d_,dmin_,dmax_}]:=Show[Graphics[ FieldTable[{a,b},{c,cmin,cmax},{d,dmin,dmax}]],Axes->Automatic] (*slight modification below due to the 3D nature of the field, each item below is similar to those above. The scale length is chosen to be .05 the diagonal length of the box *) Vec[r_,s_,i_]:=Block[{l},l=s/Sqrt[s.s];Line[{r,r+i*s}]]; FieldTable3D[a_,{x1_,x1min_,x1max_},{y1_,y1min_,y1max_},{z1_,z1min_,z1max_}]:= Block[{w},w=.05 Sqrt[(x1max-x1min)^2+(y1max-y1min)^2+(z1max-z1min)^2]; Table[{RGBColor[.5,.75,0],Point[{x1,y1,z1}],RGBColor[0,0,0],Vec[{x1,y1,z1},a, w]},{x1,x1min,x1max,(x1max-x1min)/6},{y1,y1min,y1max,(y1max-y1min)/6}, {z1,z1min,z1max,(z1max-z1min)/6}]] VectorPlot3D[a_,{x1_,x1min_,x1max_},{y1_,y1min_,y1max_},{z1_,z1min_,z1max_}]:= Show[Graphics3D[FieldTable3D[a,{x1,x1min,x1max},{y1,y1min,y1max}, {z1,z1min,z1max}]],Axes->Automatic] End[] EndPackage[]