7
$\begingroup$

This problem is probably pretty basic, but I can't find a solution anywhere.

Here's a closed surface with a nice yummy flavor :

SphericalPlot3D[
8Cos[4phi]Sin[theta]^4 - 35 - 28Cos[2theta] - Cos[4theta],
{theta, 0, Pi}, {phi, 0, 2 Pi},
ColorFunction -> Function[{x, y, z, theta, phi, r}, ColorData["Rainbow"][r]],
PlotPoints -> {32, 24},
BoundaryStyle -> None,
PlotRange -> All,
Boxed -> False,
Axes -> False,
SphericalRegion -> True,
Method -> {"RotationControl" -> "Globe"},
ImageSize -> {500, 500}
]

Now turn around it. You should notice a vertical "fold-like" line all along the surface. This is apparently a "cut" (turning the BoundaryStyle to True should reveal the border with a black line).

This is very annoying. How should I remove that cut "fold" on the surface (which should be perfectly smooth everywhere) ?

$\endgroup$
7
  • $\begingroup$ If this help, try start theta with less than 0. Try this {theta, -Pi, Pi} $\endgroup$ Mar 8, 2016 at 1:04
  • $\begingroup$ @Algohi, it cannot be ! Theta is a spherical angle, from 0 to Pi. Changing the interval to -Pi to Pi will double the surface. I tried it, and it also add some glitches at the poles. That cut line appears to be between phi = 0 and phi = 2Pi, which should be "glued" (or identified) in some way which I don't know. $\endgroup$
    – Cham
    Mar 8, 2016 at 1:10
  • $\begingroup$ Cham as @Algohi suggested, you should try setting {theta, -Pi, Pi}; in order to remove the resulting glitches, increase MaxRecursion (e.g. to MaxRecursion -> 4). Your PlotPoints setting may also need to be adjusted. $\endgroup$
    – MarcoB
    Mar 8, 2016 at 1:45
  • $\begingroup$ @MarcoB, using {theta, -Pi, Pi} gives ugly artifacts at the poles (a kind of polar pinch effect). The problem appears to be between phi = 0 and phi = 2Pi. Both values should be identified. $\endgroup$
    – Cham
    Mar 8, 2016 at 1:53
  • $\begingroup$ @Cham The following was obtained setting {theta, -Pi, Pi}, eliminating any PlotPoints directive, and setting MaxRecursion -> 5; I don't see artifacts at the poles: image. I am on Win 7-64 and MMA 10.4. $\endgroup$
    – MarcoB
    Mar 8, 2016 at 1:58

1 Answer 1

10
$\begingroup$

The reason for the line you see is probably that the surface normals aren't calculated correctly at the stitching line. Surface normals are used to give a smooth rendering even for low number of polygons. This can be fixed by specifying a NormalsFunction as follows:

f[theta_, phi_] := 
 8 Cos[4 phi] Sin[theta]^4 - 35 - 28 Cos[2 theta] - Cos[4 theta]

n[θ_, ϕ_] = 
  Apply[Cross, 
   D[f[θ, ϕ] {Cos[ϕ] Sin[θ], 
        Sin[ϕ] Sin[θ], 
        Cos[θ]}, #] & /@ {θ, ϕ}];

 SphericalPlot3D[f[theta, phi], {theta, 0, Pi}, {phi, 0, 2 Pi}, 
 NormalsFunction -> (n[#4, #5] &), 
 ColorFunction -> 
  Function[{x, y, z, theta, phi, r}, ColorData["Rainbow"][r]], 
 PlotPoints -> {32, 24}, BoundaryStyle -> None, PlotRange -> All, 
 Boxed -> False, Axes -> False, SphericalRegion -> True, 
 Method -> {"RotationControl" -> "Globe"}, ImageSize -> {500, 500}]

The resulting plot looks like the original one, but has no defective line on my system (Mac OS X, Mathematica version 10.3.1).

The only change I made was the option NormalsFunction -> (n[#4, #5] &), no change to the number of plot points was made. To construct the normals, I defined your plot function as f, and then calculated its surface normal from the spherical-coordinate parametrization using the Cross product of the tangent vectors. The latter are obtained by differentiation with respect to the angles. This is done in the function n, which returns the normal vector.

$\endgroup$
2
  • $\begingroup$ It appears to work ! Thanks a lot ! I'll study this interesting solution tomorrow, since now I'm too tired to understand anything :-( $\endgroup$
    – Cham
    Mar 8, 2016 at 4:18
  • $\begingroup$ Very nice. +1 or more $\endgroup$ Mar 8, 2016 at 4:40

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.