# 222 - Topic 20 - Vector Field Viewing 3D

## 686 days ago by Professor222

John Travis

Mississippi College

Vector Field Viewing.

In the interactive cell below, enter functions for each of the three components  of the 3D vector field $F(x,y,z) = <F_1,F_2,F_3>$.  Be certain to put your 3D glasses on for best viewing.  You may adjust your the image by RIGHT-clicking on the graphic and selecting one of the listed options.

%hide %auto var('x,y,z') @interact def _(A=input_box(default=x-sin(z),label='$F_1(x,y,z) =$'), B=input_box(default=-y*cos(z),label='$F_2(x,y,z) =$'), C=input_box(1.7*sin(z),label='$F_3(x,y,z) =$'), threed=checkbox(default=true,label='3D view'), more_pts=checkbox(default=False,label='More Vectors?')): field = (A,B,C) if more_pts: density_vectors = 8 else: density_vectors = 5 H=plot_vector_field3d(field, (x,-2,2), (y,-2,2), (z,-2,2),plot_points=density_vectors,colors=['red','green','blue'],box='False') if threed: show(H,stereo='redcyan',spin=true,figsize=(6,9)) else: show(H,spin=true,perspective_depth=true,figsize=(6,9))

 $F_1(x,y,z) =$ $F_2(x,y,z) =$ $F_3(x,y,z) =$ 3D view More Vectors?

## Click to the left again to hide and once more to show the dynamic interactive window

%auto # This routine is a copy of the built-in function "plot_vector_field3d" but where # the autoscaling feature has been disabled so that vectors are displayed using their # actual length def plot_vector_field3d_unscaled(vec, xrange, yrange, zrange, plot_points=[5,5,5], factor=1, colors='jet', center_arrows=False,**kwds): from matplotlib.cm import get_cmap from matplotlib.colors import ListedColormap from sage.plot.misc import setup_for_eval_on_grid (ff,gg,hh), ranges = setup_for_eval_on_grid(vec, [xrange, yrange, zrange], plot_points) xpoints, ypoints, zpoints = [srange(*r, include_endpoint=True) for r in ranges] points = [vector((i,j,k)) for i in xpoints for j in ypoints for k in zpoints] vectors = [vector((ff(*point), gg(*point), hh(*point))) for point in points] try: cm=get_cmap(colors) assert(cm is not None) except: if not isinstance(colors, (list, tuple)): colors=[colors] cm=ListedColormap(colors) # max_len = max(v.norm() for v in vectors) max_len = 1/factor # factor=1 means original length scaled_vectors = [v/max_len for v in vectors] if center_arrows: return sum([plot(v,color=cm(v.norm()),**kwds).translate(p-v/2) for v,p in zip(scaled_vectors, points)]) else: return sum([plot(v,color=cm(v.norm()),**kwds).translate(p) for v,p in zip(scaled_vectors, points)])
%auto var('x,y,z') @interact def _(A=input_box(default=x^2*z,label='$F_1(x,y,z) =$'), B=input_box(default=-2*x*z,label='$F_2(x,y,z) =$'), C=input_box(y*z,label='$F_3(x,y,z) =$'), threed=checkbox(default=true,label='3D view'), vector_field=checkbox(default=true,label='Show Vector Field'), curl_field=checkbox(default=true,label='Show Curl Field'), more_pts=checkbox(default=False,label='More Vectors?'), way_more_pts=checkbox(default=False,label='Lots More Vectors?'), scale_factor=slider(1/20,2,1/20,1/5)): field = (A,B,C) curlf = (derivative(C,y)-derivative(B,z),derivative(C,x)-derivative(A,z),derivative(B,x)-derivative(A,y)) if way_more_pts: density_vectors = 10 elif more_pts: density_vectors = 8 else: density_vectors = 5 H = Graphics() if vector_field: H+=plot_vector_field3d_unscaled(field, (x,-1,1), (y,-1,1), (z,0,2*pi),factor=scale_factor, plot_points=density_vectors,colors=['green','green','green'],box='False') H+=text3d("Vector Field.",(1,1,6.8),color='green') if curl_field: H+=plot_vector_field3d_unscaled(curlf, (x,-1,1), (y,-1,1), (z,0,2*pi),factor=scale_factor, plot_points=density_vectors,colors=['red','red','red'],box='False',opacity=0.5) H+=text3d("Curl Field.",(1,1,6.5)) if threed: show(H,stereo='redcyan',spin=true,figsize=(8,12)) else: show(H,spin=true,perspective_depth=true,figsize=(8,12))

$F_1(x,y,z) =$
$F_2(x,y,z) =$
$F_3(x,y,z) =$
3D view
Show Vector Field
Show Curl Field
More Vectors?
Lots More Vectors?
scale_factor

## Click to the left again to hide and once more to show the dynamic interactive window

# This is for a MC banner var('x,y,z') @interact def _(A=input_box(default=x-sin(z),label='$F_1(x,y,z) =$'), B=input_box(default=-y*cos(z),label='$F_2(x,y,z) =$'), C=input_box(1.7*sin(z),label='$F_3(x,y,z) =$'), threed=checkbox(default=true,label='3D view'), more_pts=checkbox(default=False,label='More Vectors?')): field = (A,B,C) if more_pts: density_vectors = 8 else: density_vectors = 5 H=plot_vector_field3d(field, (x,-2,2), (y,-2,2), (z,-2,2),plot_points=density_vectors,colors=['red','green','blue'],frame=0,axes=0) T = ['Math is Awesome!'] pi2 = 2*pi for n in range(16): k = n-8 H += text3d(T[0][n], (2*cos(k/pi2),2*sin(k/pi2),k/8-1),color='blue') if threed: show(H,stereo='redcyan',spin=true,figsize=(9,9)) else: show(H,spin=true,perspective_depth=true,figsize=(6,9))

 $F_1(x,y,z) =$ $F_2(x,y,z) =$ $F_3(x,y,z) =$ 3D view More Vectors?

## Click to the left again to hide and once more to show the dynamic interactive window

T = ['Math @ MC is Awesome!'] T[0][1]
 'a' 'a'