Vector Visualization

Tim McDevitt
Wolfram Research

(RowDefault[, (Spacer1), , (Spacer1), ])  #WolframTechConf

What’s New?

Versions 12.1, 12.2

Upgrades to VectorPlot, VectorDensityPlot, StreamDensityPlot, VectorPlot3D, SliceVectorPlot3D, GeoVectorPlot, and GeoStreamPlot.

Creation of ComplexVectorPlot and ComplexStreamPlot.

Version 12.3

StreamPlot3D

Version 13.0

VectorDisplacementPlot, VectorDisplacementPlot3D, ListVectorDisplacementPlot, ListVectorDisplacementPlot3D

Updates to VectorPlot

VectorPlot now uses color, does not automatically scale the vectors, uses a hexagonal packing, and arrows have a nonzero minimum length.

{VectorPlot[{y,-x},{x,-3,3},{y,-3,3},VectorColorFunction->None,VectorScaling->Automatic,VectorSizes->{0,1},VectorPoints->"Regular",PlotRangePadding->Scaled[.05],PlotLabel->"Old"],VectorPlot[{y,-x},{x,-3,3},{y,-3,3},PlotLabel->"New"]}

Note that the arrows are centered at the sample points.

pts=Flatten[Table[{x,y},{x,-2,2},{y,-2,2}],1];
VectorPlot[{y,-x},{x,-3,3},{y,-3,3},VectorColorFunction->None,VectorPoints->pts,Epilog->{Red,PointSize[0.02],Point[pts]}]

Updates to VectorPlot3D and SliceVectorPlot3D

{VectorPlot3D[{y,-x,z},{x,-3,3},{y,-3,3},{z,-3,3},VectorMarkers->"Arrow",VectorColorFunction->None,VectorSizes->{0,1},VectorPoints->Flatten[Table[{x,y,z},{x,-3,3,(6/7)},{y,-3,3,(6/7)},{z,-3,3,(6/7)}],2],VectorScaling->Automatic,PlotLabel->"Old"],
VectorPlot3D[{y,-x,z},{x,-3,3},{y,-3,3},{z,-3,3},PlotLabel->"New"]}

{SliceVectorPlot3D[{y,-x,z},"CenterPlanes",{x,-3,3},{y,-3,3},{z,-3,3},VectorMarkers->"Arrow",VectorColorFunction->None,VectorSizes->{0,1},VectorScaling->Automatic,PlotLabel->"Old",VectorStyle->Hue[0.67,0.6,0.6],ImageSize->300]/.GrayLevel[0.67]->Hue[0.11,0.5,0.7],
SliceVectorPlot3D[{y,-x,z},"CenterPlanes",{x,-3,3},{y,-3,3},{z,-3,3},PlotLabel->"New",ImageSize->300]}

ComplexVectorPlot

Consider a complex function of a complex variable f(z)=f(x+i y)=u(x,y)+i v(x,y).  ComplexVectorPlot plots the vector field {u,v} and ComplexStreamPlot plots streamlines based on {u,v}.

{ComplexVectorPlot[(z^4),{z,5}],ComplexStreamPlot[(z^4),{z,5}]}

VectorPlot and StreamPlot

Introduction

VectorPlot plots a sample of vectors in a vector field {(Subscript[v, x]),(Subscript[v, y])} and StreamPlot plots a sample of solutions of 
	x'=(Subscript[v, x])(x,y)
	y'=(Subscript[v, y])(x,y).

vectorField={y-x(((1-(x^2)-(y^2)))^2),-x-y(((1-(x^2)-(y^2)))^2)};

{VectorPlot[vectorField,{x,-3,3},{y,-3,3}],
StreamPlot[vectorField,{x,-3,3},{y,-3,3}]}

VectorPlot and StreamPlot

Application

dipoleField=(({x+1,y})/((Norm[{x+1,y}])^3))-(({x-1,y})/((Norm[{x-1,y}])^3));

{VectorPlot[dipoleField,{x,-3,3},{y,-3,3}],
StreamPlot[dipoleField,{x,-3,3},{y,-3,3}]}

VectorPlot3D and StreamPlot3D

VectorPlot3D plots a sample of vectors in a vector field {(Subscript[v, x]),(Subscript[v, y]),(Subscript[v, z])} and StreamPlot3D plots a sample of solutions of 
	x'=(Subscript[v, x])(x,y,z)
	y'=(Subscript[v, y])(x,y,z)
	z'=(Subscript[v, z])(x,y,z).

field={(y^2),1,x};

{VectorPlot3D[field,{x,-1,1},{y,-1,1},{z,-1,1}],StreamPlot3D[field,{x,-1,1},{y,-1,1},{z,-1,1}]}

Colors indicate the magnitude of the field.

StreamPlot3D Options

StreamMarkers

Use different stream markers.

field={x,y,1};

Table[StreamPlot3D[field,{x,-1,1},{y,-1,1},{z,-1,1},StreamMarkers->sm,PlotLabel->sm],{sm,{"Line","Tube","Ribbon","ArrowRibbon","Arrow","Arrow3D"}}]

StreamPlot3D Options (2)

Familiar Options from StreamPlot

StreamPlot3D[{x-3y z,3x z+y,z},{x,y,z}∈Cylinder[],StreamColorFunction->"Rainbow",PlotLegends->Automatic,StreamPoints->Coarse,StreamStyle->Directive[Dashing[{0.1,0.01}],Thickness[0.02]],RegionBoundaryStyle->Gray]

StreamPlot3D

Applications

Electric Dipole

dipoleField=(({x,y,z-1})/((Norm[{x,y,z-1}])^3))-(({x,y,z+1})/((Norm[{x,y,z+1}])^3));

Compare VectorPlot3D and StreamPlot3D.

{VectorPlot3D[dipoleField,{x,-3,3},{y,-3,3},{z,-3,3}],StreamPlot3D[dipoleField,{x,-3,3},{y,-3,3},{z,-3,3}]}

Use RegionFunction to avoid points near the poles.

StreamPlot3D[dipoleField,{x,-3,3},{y,-3,3},{z,-3,3},RegionFunction->(#7<5&),RegionBoundaryStyle->None,PlotLegends->Automatic]

Use StreamScale to make a plot like VectorPlot3D that follows field lines.

{VectorPlot3D[dipoleField,{x,-3,3},{y,-3,3},{z,-3,3}],StreamPlot3D[dipoleField,{x,-3,3},{y,-3,3},{z,-3,3},StreamMarkers->"Arrow3D",StreamScale->{0.075,2}]}

StreamPlot3D

Applications

Visualize solutions of autonomous ODEs

x'=cos(z)
y'=sin(x)
z'=sin(2y)

StreamPlot3D[{Cos[z],Sin[x],Sin[2y]},{x,-3,3},{y,-3,3},{z,-3,3},StreamPoints->Coarse]

Change the markers to long arrows to see the direction of the flow.

StreamPlot3D[{Cos[z],Sin[x],Sin[2y]},{x,-3,3},{y,-3,3},{z,-3,3},StreamMarkers->"Arrow",StreamScale->Full,StreamPoints->Coarse]

StreamPlot3D

Applications

Visualize the Lorenz attractor

StreamPlot3D[{10(y-x),x(28-z)-y,x y-(8/3) z},{x,-30,30},{y,-30,30},{z,0,50},StreamPoints->{{1,1,1}}]

StreamPlot3D

Applications

Visualize solutions on a manifold

StreamPlot3D[{-4 (x^2) y-4 (y^3)-x z,4 (x^3)+4 x (y^2)-y z,(x^2)+(y^2)},{x,-1,1},{y,-1,1},{z,-1,1},StreamPoints->SpherePoints[10]]

StreamPlot3D

Applications

Visualize the torsion of a twisted cubic

StreamPlot3D[{1,2x,3(x^2)},{x,-1,1},{y,-1,1},{z,-1,1},StreamMarkers->"Ribbon",StreamPoints->{{0,0,0}},ViewPoint->{-1.3,2.4,2}]

VectorDisplacementPlot

Introduction

For a given displacement field, show a reference region and the corresponding deformed region.  Colors are based on the norm of the displacement field.

VectorDisplacementPlot[{-y,x},{x,-1,1},{y,-1,1}]

Include arrows to illustrate where a sampling of points go under the deformation.

VectorDisplacementPlot[{-y,x},{x,-1,1},{y,-1,1},VectorPoints->Automatic]

Restrict arrows to the boundary.

VectorDisplacementPlot[{-y,x},{x,-1,1},{y,-1,1},VectorPoints->"Boundary"]

Displacements are automatically scaled.

{VectorDisplacementPlot[(10^6){-y,x},{x,-1,1},{y,-1,1},VectorPoints->"Boundary"],
VectorDisplacementPlot[(10^(-6)){-y,x},{x,-1,1},{y,-1,1},VectorPoints->"Boundary"]}

Use VectorSizes->Full to prevent scaling.

VectorDisplacementPlot[{-y,x},{x,-1,1},{y,-1,1},VectorSizes->Full]

Specify a scalar field for coloring.

VectorDisplacementPlot[{{-y,x},Sin[5π x y]},{x,-1,1},{y,-1,1},VectorSizes->Full]

Use PlotPoints to improve the quality of the plot.

VectorDisplacementPlot[{{-y,x},Sin[5π x y]},{x,-1,1},{y,-1,1},VectorSizes->Full,PlotPoints->50]

Suppress the reference region.

VectorDisplacementPlot[{{-y,x},Sin[5π x y]},{x,-1,1},{y,-1,1},VectorSizes->Full,PlotPoints->50,RegionFillingStyle->None,RegionBoundaryStyle->None]

VectorDisplacementPlot

Domain Flexibility

field={-Cos[y],Sin[x]};

VectorDisplacementPlot[field,{x,-3,3},{y,-2,2}]

VectorDisplacementPlot[field,{x,y}∈Annulus[]]

VectorDisplacementPlot[field,{x,y}∈RegionUnion[Disk[],Disk[{-1,1},0.5],Disk[{1,1},0.5]]]

VectorDisplacementPlot[field,{x,y}∈HilbertCurve[3,2]]

VectorDisplacementPlot[field,{x,y}∈ImplicitRegion[1<=(x^4)+(y^4)<=16,{x,y}]]

VectorDisplacementPlot[field,{x,y}∈MeshRegion[{{0,0},{1,1},{1,-1},{-1,1},{-1,-1}},{Polygon[{1,2,3}],Polygon[{1,4,5}]}]]

VectorDisplacementPlot[field,{x,y}∈BoundaryMeshRegion[{{0,0},{3,0},{3,3},{0,3},{1,1},{2,1},{2,2},{1,2}},Line[{1,2,3,4,1}],Line[{5,6,7,8,5}]]]

VectorDisplacementPlot[field,{x,y}∈ParametricRegion[{Cos[θ],Sin[2θ]},{{θ,0,2 π}}]]

VectorDisplacementPlot[field,{x,y}∈ParametricRegion[r{Cos[θ],Sin[2θ]},{{r,0,1},{θ,0,2 π}}]]

VectorDisplacementPlot

Applications

Visualize dilations/contractions, shears, and rotations.

Manipulate[VectorDisplacementPlot[((({{d1, 0}, {0, d2}})).(({{1, sxy}, {syx, 1}})).RotationMatrix[θ]-IdentityMatrix[2]).{x,y},{x,-1,1},{y,-1,1},
VectorSizes->Full,PlotStyle->Texture[],
BoundaryStyle->None,RegionBoundaryStyle->None,RegionFillingStyle->None,
PlotRange->2,Mesh->m],{θ,0,2π},{{sxy,0},-1,1},{{syx,0},-1,1},{{d1,1},0.01,2},{{d2,1},0.01,2},{{m,False,"Mesh"},{True,False}}]

VectorDisplacementPlot

Applications

Visualize a deformation from solid mechanics.

Consider a linearly elastic bar of length 2 L and height 2 h subjected to a moment of magnitude M at both ends:

{h,L}={1,4};
Graphics[{LightGray,Rectangle[{-L,-h},{L,h}],Black,
Arrow[Table[{-L-0.5h Sin[t],0.5h Cos[t]},{t,0,π,0.1π}]],Arrow[Table[{L+0.5h Sin[t],0.5h Cos[t]},{t,0,π,0.1π}]],Text["M",{-L-h,0}],Text["M",{L+h,0}]}]

Specify Young’s modulus, Poisson’s ratio, and the size of the applied moment.

{young,ν}={30 (10^6),0.25};
M=1;

The resulting displacement vector is

u=((3M)/(4young (h^3))){2x y,(L^2)-(x^2)-ν (y^2)};

Visualize the deformed bar.

VectorDisplacementPlot[u,{x,-L,L},{y,-h,h}]

Recall that the deformations are scaled.

VectorDisplacementPlot[u,{x,-L,L},{y,-h,h},VectorSizes->Full]

The only nontrivial stress is the normal stress in the x direction:

σxx=((3M)/(2(h^3)))y;

Color the deformed bar by (Subscript[σ, xx]):

VectorDisplacementPlot[{u,σxx},{x,-L,L},{y,-h,h},PlotLegends->Automatic]

VectorDisplacementPlot

Applications

Consider an infinite, linearly elastic, thin plate with a hole of radius a at the origin with a uniform tensile load in the horizontal direction:

a=0.5;
Ω=RegionDifference[Rectangle[{-3,-3},{3,3}],Disk[{0,0},a]];
VectorPlot[{x,0},{x,y}∈Ω,VectorPoints->Flatten[Table[{x,y},{x,{-3,3}},{y,-3,3}],1],VectorMarkers->"Start",PlotRange->4]

Plot the deformed region colored by the dimensionless hoop stress. Note the stress concentration (factor of 3) at the top and bottom of the hole.

{young,ν}={30 (10^6),0.25};
load=5;
{u,v}=((load a)/(2young)){(2(r/a)+((((a/r)))^3)(1+ν)+2(a/r)(1+ν)(1-((((a/r)))^2))Cos[2θ]+(a/r)(3-ν))Cos[θ],
(2ν(r/a)+((((a/r)))^3)(1+ν)-2(a/r)(1+ν)(1-((((a/r)))^2))Cos[2θ]+(a/r)(1-3ν))Sin[θ]}/.{r->(Sqrt[(x^2)+(y^2)]),θ->ArcTan[x,y]};
σθθ=(load/2)(1-(3((((a/r)))^4)+1)Cos[2θ]+((((a/r)))^2))/.{r->(Sqrt[(x^2)+(y^2)]),θ->ArcTan[x,y]};
VectorDisplacementPlot[{{u,v},((σθθ)/load)},{x,y}∈Ω,PlotLegends->Automatic]

(Legended[, (BarLegend)])

Including the arrows may help build intuition.

VectorDisplacementPlot[{{u,v},((σθθ)/load)},{x,y}∈Ω,PlotLegends->Automatic,VectorPoints->Automatic]

(Legended[, (BarLegend)])

VectorDisplacementPlot3D

Introduction

This is similar to VectorDisplacementPlot.

field={Cos[y],Sin[z],-Sin[x]}/5;

VectorDisplacementPlot3D[field,{x,-3,3},{y,-2,2},{z,-1,1}]

VectorDisplacementPlot3D[field,{x,-3,3},{y,-2,2},{z,-1,1},VectorSizes->Full]

VectorDisplacementPlot3D[field,{x,-3,3},{y,-2,2},{z,-1,1},VectorPoints->"Boundary"]

VectorDisplacementPlot3D also has impressive domain flexibility.

VectorDisplacementPlot3D[field,{x,y,z}∈Sphere[]]

VectorDisplacementPlot3D[field,{x,y,z}∈RegionDifference[Cuboid[{0,0,0},{1,1,1}],Cuboid[{0.25,0.5,0},{0.75,1,0.75}]]]

VectorDisplacementPlot3D[field,{x,y,z}∈HilbertCurve[2,3],PlotStyle->Thick]

VectorDisplacementPlot3D[field,{x,y,z}∈ImplicitRegion[(x^4)+(y^4)+(z^4)<=1,{x,y,z}]]

VectorDisplacementPlot3D[field,{x,y,z}∈MeshRegion[{{0,0,0},{2,0,0},{2,2,0},{0,2,0},{1,1,2}},{Tetrahedron[{1,2,3,5}],Tetrahedron[{1,3,4,5}]}]]

VectorDisplacementPlot3D[field,{x,y,z}∈BoundaryMeshRegion[{{0,0,0},{1,0,0},{0,1,0},{0,0,1}},Polygon[{{1,2,3},{1,2,4},{2,3,4},{1,3,4}}]]]

VectorDisplacementPlot3D[field,{x,y,z}∈ParametricRegion[{t,Cos[5t],Sin[5t]},{{t,0,2π}}],PlotStyle->Thick,RegionFillingStyle->Directive[Thick,LightGray]]

VectorDisplacementPlot3D[field,{x,y,z}∈ParametricRegion[{r Cos[θ],r Sin[θ],(r^2)},{{r,0,1},{θ,0,2π}}]]

VectorDisplacementPlot3D

Application

Consider an elliptic cylinder centered on the z-axis.

{a,b}={2,1};
Ω=ImplicitRegion[((x^2)/(a^2))+((y^2)/(b^2))≤1&&-3≤z≤3,{x,y,z}];

Apply constant torque T  to the ends of the bar.

Show[Region[Ω],Graphics3D[{Black,Arrow[Tube[Table[{Cos[t],Sin[t],3.5},{t,0,6,0.1}]]],Arrow[Tube[Table[{Cos[t],-Sin[t],-3.5},{t,0,6,0.1}]]],Text["T",{1.3,0,3.5}],Text["T",{1.3,0,-3.5}]}],ImageSize->Small]

Specify the magnitude of the applied torque:

T=1;

If the material is linearly elastic with shear modulus μ, then the resulting displacement field is:

μ=80; 
displacement=(T/((a^3) (b^3) π μ)){-((a^2)+(b^2))  y z,((a^2)+(b^2))  x z,((b^2)-(a^2))  x y};

Use a mesh to illustrate the twisting of the bar:

VectorDisplacementPlot3D[displacement,{x,y,z}∈Ω,Mesh->3,RegionFillingStyle->None,RegionBoundaryStyle->None,BoundaryStyle->None]

Compute the nontrivial shear stresses:

{σxz,σyz}=((2T)/(π a b)){-(y/(b^2)),(x/(a^2))};

Use the shear stresses to color the region:

{VectorDisplacementPlot3D[{displacement,σxz},{x,y,z}∈Ω,Mesh->3,RegionFillingStyle->None,RegionBoundaryStyle->None,BoundaryStyle->None,PlotLabel->"(Subscript[σ, xz])"],
VectorDisplacementPlot3D[{displacement,σyz},{x,y,z}∈Ω,Mesh->3,RegionFillingStyle->None,RegionBoundaryStyle->None,BoundaryStyle->None,PlotLabel->"(Subscript[σ, yz])"]}

VectorDisplacementPlot3D

Application

Compute the deflection of a spoon held fixed at the end and with a force applied at the top.

Set up variables and physical parameters:

vars={{u[x,y,z],v[x,y,z],w[x,y,z]},{x,y,z}};
pars=<|"Material"->(Entity["silver", Entity["Element","Silver"], "Entity[\"Element\", \"Silver\"]", "element"])|>;

Set up the PDE and the geometry:

spoon=;
{d1,d2,d3}=NDSolveValue[{SolidMechanicsPDEComponent[vars,pars]==SolidBoundaryLoadValue[x>=1/10,vars,pars,<|"Force"->{0,0,(Quantity[-100, "N", newtons, "Newtons"])}|>],
SolidFixedCondition[x<=-1/10,vars,pars]},{u,v,w},{x,y,z}∈spoon];

Visualize the deformed spoon:

VectorDisplacementPlot3D[{d1[x,y,z],d2[x,y,z],d3[x,y,z]},{x,y,z}∈spoon]

ListVectorDisplacementPlot

Introduction

ListVectorDisplacementPlot is similar to VectorDisplacementPlot, but it works with data instead of a formula for the field.

data=Table[{{x,y},{Sin[y],Cos[x]}},{x,-1,1,0.1},{y,-1,1,0.1}];

ListVectorDisplacementPlot[data,Annulus[]]

ListVectorDisplacementPlot3D

Introduction

ListVectorDisplacementPlot3D is similar to VectorDisplacementPlot3D, but it works with data instead of a formula for the field.

data=Table[{{x,y,z},{Sin[y],Cos[x],Sin[z]}},{x,-1,1,0.1},{y,-1,1,0.1},{z,-1,1,0.1}];

ListVectorDisplacementPlot3D[data,Cylinder[]]

Questions?

Feel free to email me at timothym@wolfram.com.