I want to draw sphere segments, I made a sketch here: sphere segments

An optional bonus would be to separate the segments slightly in x1 direction. Any help would be appreciated!


All I am doing here is to apply the IMHO extremely neat macros from this great answer.

% Declare nice sphere shading: http://tex.stackexchange.com/a/54239/12440

% Style to set TikZ camera angle, like PGFPlots `view`
\tikzset{viewport/.style 2 args={

% Styles to plot only points that are before or behind the sphere.
\pgfplotsset{only foreground/.style={
    restrict expr to domain={rawx*\CameraX + rawy*\CameraY + rawz*\CameraZ}{-0.05:100},
\pgfplotsset{only background/.style={
    restrict expr to domain={rawx*\CameraX + rawy*\CameraY + rawz*\CameraZ}{-100:0.05}

% Automatically plot transparent lines in background and solid lines in foreground
    \addplot3[#1,only background, opacity=0.25] #2;
    \addplot3[#1,only foreground] #2;


    % Compute camera unit vector for calculating depth
    %\path[use as bounding box] (-1.2*\Radius,-1.2*\Radius) rectangle (\Radius,\Radius); % Avoid jittering animation
    % Draw a nice looking sphere
        \clip[name path global=sphere] (0,0) circle (\Radius*1cm);
        \begin{scope}[transform canvas={rotate=-200}]
            \shade [ball color=white] (0,0.5*\Radius) ellipse (\Radius*1.8 and
        hide axis,
        view={\ViewAzimuth}{\ViewElevation},     % Set view angle
        every axis plot/.style={very thin},
        disabledatascaling,                      % Align PGFPlots coordinates with TikZ
        anchor=origin,                           % Align PGFPlots coordinates with TikZ
        viewport={\ViewAzimuth}{\ViewElevation}, % Align PGFPlots coordinates with TikZ
        % draw axis by hand
        \draw[dashed] (0,0,0) -- (-1*\Radius,0,0);
        \path[name path=xaxis] (0,0,0) --   (0,pi*\Radius,0);
        \draw[dashed,name intersections={of=xaxis and sphere,by=X}]     
        (0,0,0) --  (X);
        \path[name path=yaxis,draw,dashed] (0,0,0) --   (0,0,1.4*\Radius);
        \draw[dashed,name intersections={of=yaxis and sphere,by=Y}]     
        (0,0,0) --  (Y);
        % Plot the surfaces
        \addFGBGplot[domain=0:2*pi, samples=51, samples y=11,smooth,
        domain y=-\DeltaPhi:\DeltaPhi,surf,shader=flat,color=blue,opacity=0.9] 
            {\Radius*sin(deg(x))*cos(y)}, {\Radius*sin(y)});
        \addFGBGplot[domain=0:2*pi, samples=51, samples y=11,smooth,
        domain y=3*\DeltaPhi:5*\DeltaPhi,surf,shader=flat,color=red,opacity=0.9] 
            {\Radius*sin(deg(x))*cos(y)}, {\Radius*sin(y)});
        %draw the grand circle and equator  
        \addFGBGplot[domain=0:2*pi, samples=101, samples y=1,smooth,
        domain y=3*\DeltaPhi:5*\DeltaPhi,surf,shader=flat,thick,color=black] 
        \addFGBGplot[domain=0:2*pi, samples=101, samples y=1,smooth,
        domain y=3*\DeltaPhi:5*\DeltaPhi,surf,shader=flat,thick,color=black] 
            {\Radius*sin(deg(x))}, {0});
        % continue drawing axes         
        \draw[-latex]   (-\Radius,0,0) --   (-1.4*\Radius,0,0)
        \draw[-latex]   (X) --  (0,pi*\Radius,0) coordinate (Xend)
        \draw[-latex]   (Y) --  (0,0,1.4*\Radius) coordinate (Yend)
        % angle arc 
        \draw[-latex] let \p1=($(Xend)-(0,0,0)$),\n1={atan2(\y1,\x1)},
        \p2=($0.85*(Yend)$),\n2={veclen(\y2,\x2)} in 
        ($0.85*(Yend)$) arc(90:\n1:\n2) node[midway,above=4pt,rotate=90]{$\varphi$};

enter image description here

Let me remark that users who do not provide an MWE on this site sometimes have the reputation to make tons of additional requests in form of comments instead of asking separate questions (which is free after all). I hope that this prejudice does not apply to you.

| improve this answer | |
  • Very neat result ! – BambOo Nov 15 '18 at 18:04
  • What does MWE mean? – Rainb Jan 6 at 12:09

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.