Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- scalarField = x^2 - y^2 - z;
- vectorField = D[scalarField, {{x, y, z}}]
- v = VectorPlot3D[vectorField, {x, -2, 2}, {y, -2, 2}, {z, -2, 2},
- VectorPoints -> 20, VectorScale -> {0.1, Scaled[0.5]},
- RegionFunction -> Function[{x, y, z}, -0.1 <= scalarField <= 0.1],
- VectorStyle -> "Arrow3D", VectorColorFunction -> "Rainbow"]
- c = ContourPlot3D[
- scalarField == 0, {x, -2, 2}, {y, -2, 2}, {z, -2, 2}, Mesh -> 20,
- MeshStyle -> Opacity[.1],
- ContourStyle -> Directive[Green, Opacity[0.3], Specularity[White, 30]]]
- Show[v, c]
- σ[u_, v_] := {(2 + Cos[v]) Cos[u], (2 + Cos[v]) Sin[u], Sin[v]}
- n[u_, v_] := Evaluate[Normalize[
- Cross[D[σ[u, v], u], D[σ[u, v], v]]
- ]]
- surfacePlot =
- ParametricPlot3D[σ[u, v], {u, -Pi, Pi}, {v, -Pi, Pi},
- PlotRangePadding -> 1];
- normalPlot =
- ParametricPlot3D[n[u, v], {u, -Pi, Pi}, {v, -Pi, Pi},
- PlotStyle -> Opacity[0.5]];
- Manipulate[
- {Show[{
- surfacePlot,
- Graphics3D[{Thick, Red,
- Arrow[{σ @@ pt, σ @@ pt + n @@ pt}]}]
- }],
- Show[{
- normalPlot,
- Graphics3D[{Thick, Red, Arrow[{{0, 0, 0}, n @@ pt}]}]
- }]
- }
- ,
- {pt, {-Pi, -Pi}, {Pi, Pi}}]
- Show[{
- surfacePlot,
- Graphics3D[
- Table[
- Arrow[{σ[u, v], σ[u, v] + n[u, v]}],
- {u, -Pi, Pi, 0.4}, {v, -Pi, Pi, 0.4}]
- ]
- }]
- UnitNormalVector[f_, {u_, u0_}, {v_, v0_}] := Block[{f0, g0},
- f0 = f /. {u -> u0, v -> v0};
- g0 = Transpose[D[f, {{u, v}}] /. {u -> u0, v -> v0}];
- Arrow[{f0, f0 + Normalize[Cross @@ g0]}]]
- (* Möbius strip *)
- mobius[u_, v_] :=
- {(3 + (1/2 - v) Cos[u/2]) Cos[u], (3 + (1/2 - v) Cos[u/2]) Sin[u], (1/2 - v) Sin[u/2]}
- Show[ParametricPlot3D[mobius[u, v], {u, 0, 2 π}, {v, 0, 1},
- Mesh -> False, PlotPoints -> 55],
- Graphics3D[Table[UnitNormalVector[mobius[u, v], {u, u0}, {v, v0}],
- {u0, 0, 2 π, 2 π/20}, {v0, 0, 1, 1/5}]], PlotRange -> All]
- % /. Arrow[stuff__] :> {Blue, Arrow[Tube[stuff, 0.05]]}
- normalsShow[g_Graphics3D] :=
- Module[{pl, vl, n},
- {pl, vl} = First @ Cases[g,
- GraphicsComplex[pl_, prims_, VertexNormals -> vl_,
- opts___?OptionQ] :> {pl, vl}, ∞];
- n = Length[pl];
- Show[g,
- Graphics3D[
- GraphicsComplex @@ {Join[pl, pl + vl/3], {Black,
- Line[Table[{i, i + n}, {i, n}]]}}]]
- ];
- c // normalsShow
- surfacePlot // normalsShow
- ParametricPlot3D[mobius[u, v], {u, 0, 2 π}, {v, 0, 1},
- Mesh -> False, PlotPoints -> 55] // normalsShow
Add Comment
Please, Sign In to add comment