2
$\begingroup$

I have a problem with VectorPlot and Plot3D, and I have a code for both but I dont know how to plot the same figure. Here is the code for Plot3D:

Ω = Rectangle[{0, 0}, {1, 1}];
op = Laplacian[u[x, y], {x, y}] + 2;
Subscript[Γ, D] = {DirichletCondition[u[x, y] == 0, True]};
Φ = NDSolveValue[{op == 0, Subscript[Γ, D]}, u, {x, y} ∈ Ω];
Plot3D[{-Subscript[τ, yz] - Subscript[τ, xz]}, {x, y} ∈ Ω, PlotStyle -> None, 
    PlotTheme -> "Detailed", Mesh -> True, 
    AxesLabel -> {"x", "y", "\!\(\*SubscriptBox[\(τ\), \(zy\)]\)(x,y)"}, 
    LabelStyle -> Directive[FontFamily -> "Courier New"]]

And the code for VectorPlot:

Subscript[τ, yz] = -\!\(\*SubscriptBox[\(∂\), \(x\)]\(Φ[x, y]\)\);
Subscript[τ, xz] = \!\(\*SubscriptBox[\(∂\), \(y\)]\(Φ[x, y]\)\);
VectorPlot[{Subscript[τ, xz],  Subscript[τ, yz]}, {x, 0, 1}, {y, 0, 1}]

I found this link but I dont understand how can use for my code: http://community.wolfram.com/groups/-/m/t/26013 enter image description here

$\endgroup$
3
$\begingroup$
I have changed so solution and vector plot match:

Subscript[τ, yz] = -D[Φ[x, y], x]; 
Subscript[τ, xz] = D[Φ[x, y], y]; 

vp = VectorPlot[{Subscript[τ, xz], Subscript[τ, yz]}, {x, 0, 1}, {y, 0, 1}]; 
Ω = Rectangle[{0, 0}, {1, 1}]; 
op = Laplacian[u[x, y], {x, y}] + 2; 

Subscript[Γ, D] = {DirichletCondition[u[x, y] == 0, True]}; 

Φ =  NDSolveValue[{op == 0, Subscript[Γ, D]}, u,  Element[{x, y}, Ω]]; 

p = Plot3D[Φ[x, y], Element[{x, y}, Ω], PlotStyle -> None
  , PlotTheme -> "Detailed", Mesh -> True,  AxesLabel -> {"x", "y", 
     "\!\(\*SubscriptBox[\(τ\), \(zy\)]\)(x,y)"}, 
       LabelStyle -> Directive[FontFamily -> "Courier New"]
];

ar = Graphics3D[{Arrowheads[0.02], 
    Blue, (Arrow[PadRight[#1, {Length[#1], 2, 3}, 0]] & )[
           Cases[vp, Arrow[l_] :> l, -1]]}]; 

Show[p, ar]

sd

This is just application from the community code. The arrows from the VectorPlot are extracted using Cases. They are then padded with z- coordinate relevant for your plot and with what style/format desired.

$\endgroup$
  • $\begingroup$ Why did you prefer recasting vp as ar instead of using Texture[vp]? Thanks. $\endgroup$ – bbgodfrey Apr 24 '15 at 12:48
  • $\begingroup$ @bbgodfrey I adapted the code from the link in OP question...which I thought was his desired approach. Texture can produce desired effect but depending on situation requires dealing with axis offsets and other distortions...cannibalising 2D graphics object and repotting as 3D avoids this and makes easier to alter elements. $\endgroup$ – ubpdqn Apr 24 '15 at 23:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.