5

This question follows from the example below

Mapping StreamPlot onto spherical surfaces

When I'm trying to remove the arrows I cannot get the 3d graphics:

sp = StreamPlot[{Cot[θ] Cos[ϕ], -Sin[ϕ]}, {ϕ, -π, π}, {θ, 0, π},  
   StreamColorFunction -> Hue, 
   StreamScale -> None, ImageSize -> 200];

sp3d = Graphics3D[
   sp[[1]] /. 
    Arrow[z_] :> 
     Arrow[z /. {x_Real, y_Real} :> {Cos[x] Sin[y], Sin[y] Sin[x], 
         Cos[y]}], ImageSize -> 200];
Row[{sp, sp3d}, Spacer[5]]

The result is below. Any idea how to get the 3d graphics without the arrows?

enter image description here

Jason B.
  • 68,381
  • 3
  • 139
  • 286
jarhead
  • 2,065
  • 12
  • 19

2 Answers2

4

The sp output includes a GraphicsComplex, so the arguments of the primitives are indices into the GraphicsComplex and not coordinates. Also, your StreamPlot uses Line primitives instead of Arrow primitives. So, a corrected version would be:

Graphics3D[
    ReplaceAll[
        Normal[sp][[1]],
        Line[z_]:>Line[z/.{x_Real,y_Real}:>{Cos[x] Sin[y],Sin[y] Sin[x],Cos[y]}]
    ]
]

enter image description here

Note that Normal modifies the colors, so an alternative is to transform the GraphicsComplex:

Graphics3D[
    ReplaceAll[
        sp[[1]],
        {x_Real,y_Real}:>{Cos[x] Sin[y],Sin[y] Sin[x],Cos[y]}
    ],
    ImageSize->400
]

enter image description here

The latter method is identical to @Jason's now deleted answer.

Carl Woll
  • 130,679
  • 6
  • 243
  • 355
2

You can also post-process the graphics objects sp and sp3d from the accepted answer in the the linked q/a (1) to change Arrows to Lines or (2) to change the Arrowheads directive to Arrowheads[0]:

sp = StreamPlot[{Cot[θ] Cos[ϕ], -Sin[ϕ]}, {ϕ, - π, π}, {θ, 0, π}, 
  StreamColorFunction -> Hue, ImageSize -> 200];
sp3d = Graphics3D[sp[[1]] /.  Arrow[z_] :>  
     Arrow[z /. {x_Real, y_Real} :> {Cos[x] Sin[y], Sin[y] Sin[x], Cos[y]}], 
  ImageSize -> 200];

Row[{sp, sp3d} /. Arrow -> Line, Spacer[5]]

enter image description here

Row[{sp, sp3d} /. Arrowheads[_] :> Arrowheads[0], Spacer[5]]

same picture

kglr
  • 394,356
  • 18
  • 477
  • 896