5

I'm trying to make 3d plot. Unfortunately, I can't succeed in getting the desired figure, as shown below.

Here is the figure, where it's a sphere have a charge of -1 inside. And coordinate axes are supposed to be blur inside the sphere may not be dashed. enter image description here Still a MWE:

%% Copyright 2009 Jeffrey D. Hein
%
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.3
% of this license or (at your option) any later version.
% The latest version of this license is in
%   http://www.latex-project.org/lppl.txt
% and version 1.3 or later is part of all distributions of LaTeX
% version 2005/12/01 or later.
%
% This work has the LPPL maintenance status `maintained'.
% 
% The Current Maintainer of this work is Jeffrey D. Hein.
%
% This work consists of the files 3dplot.sty and 3dplot.tex

%Description
%-----------
%3dplot.tex - an example file demonstrating the use of the 3dplot.sty package.

%Created 2009-11-07 by Jeff Hein.  Last updated: 2009-11-09
%----------------------------------------------------------

%Update Notes
%------------

%2009-11-07: Created file along with 3dplot.sty package


\documentclass{article}
\usepackage{tikz}   %TikZ is required for this to work.  Make sure this exists before the next line

\usepackage{3dplot} %requires 3dplot.sty to be in same directory, or in your LaTeX installation

\usepackage[active,tightpage]{preview}  %generates a tightly fitting border around the work
\PreviewEnvironment{tikzpicture}
\setlength\PreviewBorder{2mm}

\begin{document}

    %Angle Definitions
    %-----------------

    %set the plot display orientation
    %synatax: \tdplotsetdisplay{\theta_d}{\phi_d}
    \tdplotsetmaincoords{45}{135}

    %define polar coordinates for some vector
    %TODO: look into using 3d spherical coordinate system
    \pgfmathsetmacro{\rvec}{.8}
    \pgfmathsetmacro{\thetavec}{45}
    \pgfmathsetmacro{\phivec}{60}

    %start tikz picture, and use the tdplot_main_coords style to implement the display 
    %coordinate transformation provided by 3dplot
    \begin{tikzpicture}[scale=5,tdplot_main_coords]

    % Teken eerst de bol
    \shade[tdplot_screen_coords,ball color = white] (0,0) circle (\rvec);

    %set up some coordinates 
    %-----------------------
    \coordinate (O) at (0,0,0);

    %determine a coordinate (P) using (r,\theta,\phi) coordinates.  This command
    %also determines (Pxy), (Pxz), and (Pyz): the xy-, xz-, and yz-projections
    %of the point (P).
    %syntax: \tdplotsetcoord{Coordinate name without parentheses}{r}{\theta}{\phi}
    \tdplotsetcoord{P}{\rvec}{\thetavec}{\phivec}

    %draw figure contents
    %--------------------

    %draw the main coordinate system axes
    \draw[thick,->] (0,0,0) -- (-1.5,0,0)-- (1.5,0,0) node[anchor=north east]{$x$};
    \draw[thick,->] (0,0,0) -- (0,-1.5,0)--(0,1.5,0) node[anchor=north west]{$y$};
    \draw[thick,->] (0,0,-1) -- (0,0,-1.5)-- (0,0,1.5) node[anchor=south]{$z$};





    \end{tikzpicture}

\end{document}

Edited image: enter image description here

9

Based on tikz-3dplot package definitions.

\documentclass{article}
\usepackage{tikz}   
\usepackage{tikz-3dplot}

\begin{document}

%Angle Definitions
%-----------------

%set the plot display orientation
%syntax: \tdplotsetdisplay{\theta_d}{\phi_d}
\tdplotsetmaincoords{65}{110}
\pgfmathsetmacro{\rvec}{1}
\pgfmathsetmacro{\thetavecc}{55}
\pgfmathsetmacro{\phivecc}{35}
\pgfmathsetmacro{\thetaveccc}{39.7}
\pgfmathsetmacro{\phiveccc}{55}

\begin{tikzpicture}[scale=5,tdplot_main_coords,>=latex]

\shadedraw[tdplot_screen_coords,ball color = white] (0,0) circle (\rvec);
\node[tdplot_screen_coords,xshift=1cm,yshift=3mm] (0,0) {$q=-1$};

\def\h{1} 

%-----------------------
\coordinate (O) at (0,0,0);

%draw the main coordinate system axes
\draw[thick,opacity=0.5] (0,0,0) -- (1,0,0);
\draw[thick,opacity=0.5] (0,0,0) -- (0,1,0);
\draw[thick,opacity=0.5] (0,0,0) -- (0,0,1);
\draw[thick,->] (1,0,0) -- (2.3,0,0) node[anchor=north east]{$x$};
\draw[thick,->] (0,1,0) -- (0,1.5,0) node[anchor=north west]{$y$};
\draw[thick,->] (0,0,1) -- (0,0,1.5) node[anchor=south]{$z$};

% Equator 
\draw[dashed] (\rvec,0,0) arc (0:360:\rvec);
\draw[thick] (\rvec,0,0) arc (0:110:\rvec);
\draw[thick] (\rvec,0,0) arc (0:-70:\rvec);

% Flux arrows
\foreach \t in {10,20,...,340}
        \foreach \f in {180,170,...,0}
            \draw [black!60,opacity=1.0, <-, thick]
                ({sin(\f - \h)*cos(\t - \h)}, {sin(\f - \h)*sin(\t - \h)}, {cos(\f - \h)})
                -- ({(1 + 0.2*cos(90 - \f))*sin(\f - \h)*cos(\t - \h)},
                    {(1 + 0.2*cos(90 - \f))*sin(\f - \h)*sin(\t - \h)},
                    {(1 + 0.2*cos(90 - \f))*cos(\f - \h)});

\end{tikzpicture}
\end{document}

enter image description here

  • Thanks! Is there a way to decrease the intensity of the arrows? Also maybe the color of the sphere? – Shamina Feb 22 at 13:05
  • 1
    @Shamina, your welcome. To decrease the intensity of the arrows, change the increment or decrement of the \foreach loops in Flux arrows definitions. For example \foreach \t in {10,30,...,340} and so on. For color of sphere, insert opacitiy key in \shadedraw. For example, \shadedraw[tdplot_screen_coords,ball color = white,opacity=0.5] (0,0) circle (\rvec); – ferahfeza Feb 22 at 13:18
  • Just one last question, what decides the length of arrows? – Shamina Feb 22 at 16:31
  • 1
    In flux arrows section, change the multiplier of cos, say (1 + 0.5*cos(90 - \f)). – ferahfeza Feb 22 at 16:56
  • 1
    This is a very nice answer, +1. May I suggest to draw the thing in 3 steps? 1. arrows in the background. 2. Sphere. 3. Arrows in the foreground. – user121799 Feb 22 at 17:29
4

The following code does draw the sphere (above the axes to hide them) and the -1. It uses tikz-3dplot which is in TeX Live.

with flux arrows

\documentclass[tikz]{standalone}
\usepackage{tikz-3dplot}

\begin{document}
    \tdplotsetmaincoords{60}{135}

    \pgfmathsetmacro{\rvec}{.8}

    \begin{tikzpicture}[scale=5,tdplot_main_coords]
    \coordinate (O) at (0,0,0);

    \draw[thick,->] (-1.5,0,0)-- (1.5,0,0) node[anchor=north east]{$x$};
    \draw[thick,->] (0,-1.5,0)--(0,1.5,0) node[anchor=north west]{$y$};
    \draw[thick,->] (0,0,-1.5)-- (0,0,1.5) node[anchor=south]{$z$};

    \shade[tdplot_screen_coords,ball color = white] (0,0) circle (\rvec);

    \foreach \i in {0,20,...,360}
      \draw[tdplot_screen_coords,<-] (\i:.9*\rvec) -- (\i: 1.1*\rvec);

    \node[tdplot_screen_coords] (0,0) {$-1$};
    \end{tikzpicture}
\end{document}
  • Thanks a lot! Is there a way to get those flux arrows(pointing inside the sphere) also? Is there a way to get an equator? Also the axes to be seen but bit blur inside the sphere? – Shamina Feb 22 at 11:40
  • @Shamina I have added some arrows. Could you please edit your question to make the other requirements more clear (which type of blurring do you refer to and where do you want the equator to be)? – TeXnician Feb 22 at 11:48
  • I edited my answer. I mean blurring inside the sphere – Shamina Feb 22 at 13:02

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.