5

I want to get a graphic like this.

I'm trying to apply the angle on the Z axis as it is in the figure, but I do not know where I should change.

Imagem

\documentclass{article}
\usepackage{pgfplots}
%\pgfplotsset{compat=1.11}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
axis equal,
axis lines = center,
width = 10cm,
height = 10cm,
xlabel = {$x$},
ylabel = {$y$},
zlabel = {$z$},
zmax=1.1,
view/h=135,
every axis x label/.style={ at={(ticklabel* cs:1.05)}},
every axis y label/.style={ at={(ticklabel* cs:1.05)}},
every axis z label/.style={ at={(ticklabel* cs:1.05)}}
]
\addplot3[surf, opacity = 0.5,samples=21, domain=0:1, y domain=0:0.5*pi, z buffer=sort](0, {sqrt( 1-x^2 ) * sin(deg(y))}, x);
\addplot3[surf, opacity = 0.5,samples=21, domain=0:1, y domain=0:0.5*pi, z buffer=sort]({sqrt(1-x^2) * cos(deg(y))}, {sqrt( 1-x^2 ) * sin(deg(y))}, x);
\addplot3[surf, opacity = 0.5,samples=21, domain=0:1, y domain=0:0.5*pi, z buffer=sort]({sqrt(1-x^2) * cos(deg(y))},0, x);
\end{axis}
\end{tikzpicture}
\end{document}

And I'm also not finding what I should modify so that the radius is 3 and not 1.

I tried to change zmax, but it did not work.

4
  • If you want your sphere to contain the point (1,3,0), then its radius would rather be sqrt(10), wouldn't it ?
    – marsupilam
    Jun 23, 2017 at 21:13
  • @marsupilam Really. The initial idea is of a colleague. I'll have to confirm more details.
    – LCarvalho
    Jun 23, 2017 at 21:19
  • r=Sqrt(3^2+1^2)
    – LCarvalho
    Jun 23, 2017 at 21:20
  • I have removed the [geometry] tag, as that applies explicitly to the geometry package. Replaced by [shapes]. Nov 22, 2019 at 3:20

1 Answer 1

13

Realized I plotted the wrong part of the sphere, as compared to your drawing

The output

enter image description here

The code

\documentclass[12pt,tikz]{standalone}
\usepackage{pgfplots}
%\pgfplotsset{compat=1.11}
\pgfplotsset{compat=1.14}
\begin{document}
\begin{tikzpicture}
  \tikzset
  {%
    shadedAreas/.style=
    {
      fill=blue, 
      fill opacity=.4,
    }
  }%
\begin{axis}
  [
    axis equal,
    axis lines = center,
    width = 10cm,
    height = 10cm,
    xlabel = {$x$},
    ylabel = {$y$},
    zlabel = {$z$},
    %zmax=1.1,
    view/h=135,
    every axis x label/.style={ at={(ticklabel* cs:1.05)}},
    every axis y label/.style={ at={(ticklabel* cs:1.05)}},
    every axis z label/.style={ at={(ticklabel* cs:1.05)}},
    xtick=\empty,
    ytick=\empty,
    ztick=\empty,
    extra x ticks={1},
    extra y ticks={3},
    %xmin=0,  % not working, don't know why...
    xmax=1.7,
  ]
  \pgfmathsetmacro{\thetaStart}{atan(3)}
  \xdef\thetaEnd{90}
  \pgfmathsetmacro{\r}{sqrt(10)}
  \def\f{1.2}

  % behind plane
  \addplot3[surf, opacity = 0.6,samples=2, domain=0:\f*\r, y domain=0:4, z buffer=sort](0,x,y);
  % blue disks sections
  \addplot3[samples=51,samples y=0,  domain=0:90, shadedAreas] ({\r*cos(\thetaEnd)*cos(x)}, {\r*sin(\thetaEnd)*cos(x)}, {\r*sin(x)}) \closedcycle;
  % the sphere wedge
  \addplot3 
  [surf, opacity = 0.6,samples=21, domain=0:90, y domain=\thetaStart:\thetaEnd, z buffer=sort]
  ( { \r*cos(x)*cos(y) }, { \r*cos(x) * sin(y) }, { \r*sin(x) } );
  % front plane
  \addplot3[surf, opacity = 0.6,samples=2, domain=0:\f, y domain=0:4, z buffer=sort](x, 3*x, y);
  %
  \addplot3[samples=51,samples y=0,  domain=0:90, shadedAreas] ({\r*cos(\thetaStart)*cos(x)}, {\r*sin(\thetaStart)*cos(x)}, {\r*sin(x)}) \closedcycle;

  \draw (1,0,0) -- (1,3,0) -- (0,3,0) ;

\end{axis}
\end{tikzpicture}
\end{document}
4
  • Wow! I really need to review the concept
    – LCarvalho
    Jun 23, 2017 at 21:23
  • Your response is excellent. Not even an ellipsis could be possible.
    – LCarvalho
    Jun 24, 2017 at 23:22
  • @LCarvalho Thank you very much ! (again ;))
    – marsupilam
    Jun 25, 2017 at 8:49
  • While I'm at it, the settings samples=41, samples y=7, (or so...) for the sphere wedge (in the \addplot3[surf,...) may be better-looking, in this geometrical configuration.
    – marsupilam
    Jul 5, 2017 at 9:52

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.