Let's say that you have a three dimensional surface defined by two parameters. E.g.

$$ S(\theta,\phi) = \{\cos{\theta}\sin{\phi},\sin{\theta}\sin{\phi},\cos{\phi}\} $$

Additionally, you have some normal vectors at each point on the surface, which are defined by

$$N(\theta,\phi)=\frac{\partial S}{\partial \theta} \times \frac{\partial S}{\partial \phi}$$

How could you plot the normal vectors on the surface in Mathematica? I have tried:

surfacedata = Flatten[Table[mysurface[u, v], {u, 0, 2Pi},{v, 0, Pi}], 1]
normaldata =  Flatten[Table[mynormals[u, v], {u, 0, 2Pi},{v, 0, Pi}], 1]

but to no avail.

  • 1
    $\begingroup$ The Mathematica code for mysurface and mynormals is missing. 2Pi should be 2 Pi. $\endgroup$
    – Karsten7
    Apr 21, 2016 at 23:18

1 Answer 1


You can plot the surface and the vector fields separately and then combine them together.

Here is an example. Consider the spherical radius r can be written as function $r(\theta,\phi)$:

mysurface[θ_, ϕ_] = 
 FullSimplify[Re[SphericalHarmonicY[3, 2, θ, ϕ]], 
  Assumptions -> {θ ∈ Reals, ϕ ∈ Reals}]

1/4 Sqrt[105/(2 π)] Cos[θ] Cos[2 ϕ] Sin[θ]^2

Then the surface can be plotted using SphericalPlot3D

p1 = SphericalPlot3D[
  mysurface[θ, ϕ], {θ, 0, π}, {ϕ, 0, 
   2 π}, PlotStyle -> Opacity[0.5]]

enter image description here

Now we construct the r in Cartesian coordinates

mysurfaceXYZ[x_, y_, z_] = 
   TransformedField["Spherical" -> "Cartesian", 
    mysurface[θ, ϕ], {r, θ, ϕ} -> {x, y, z}]];

and the surface in Cartesian coordinates satisfies the equation mysurfaceXYZ[x,y,z]=sqrt[x^2+y^2+z^2], which defines a scalar field.

scalerField = 
  Simplify[(Sqrt[x^2 + y^2 + z^2] - mysurfaceXYZ[x, y, z])*(Sqrt[
     x^2 + y^2 + z^2])];

The scaling factor Sqrt[x^2 + y^2 + z^2] is just to make the scalar have a more uniform value at different r.

Then the vector field can be constructed easily

vectorField = D[scalerField, {{x, y, z}}];

Now we can use the VectorPlot3D to plot the norms. The RegionFunction can be used to confine the vector field to near the surface

VectorPlot3D[vectorField, {x, -1/2, 1/2}, {y, -1/2, 1/2}, {z, -1/2, 
  1/2}, VectorPoints -> 50, 
 RegionFunction -> 
  Function[{x, y, z}, 
   Abs[Sqrt[x^2 + y^2 + z^2] - mysurfaceXYZ[x, y, z]] <= 0.05 && 
    Abs[x] >= 0.02 && Abs[y] >= 0.02 && Abs[z] >= 0.02], 
 VectorScale -> 0.05]

enter image description here

Finally, combine them together we have

enter image description here


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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