Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- documentclass[tikz,border=3.14mm]{standalone}
- usepackage{tikz-3dplot}
- usepgfmodule{nonlineartransformations}
- usepackage{mathtools}
- % Max magic
- makeatletter
- % the first part is not in use here
- deftikz@scan@transform@one@point#1{%
- tikz@scan@one@pointpgf@process#1%
- pgf@pos@transform{pgf@x}{pgf@y}}
- tikzset{%
- grid source opposite corners/.code args={#1and#2}{%
- pgfextract@processtikz@transform@source@southwest{%
- tikz@scan@transform@one@point{#1}}%
- pgfextract@processtikz@transform@source@northeast{%
- tikz@scan@transform@one@point{#2}}%
- },
- grid target corners/.code args={#1--#2--#3--#4}{%
- pgfextract@processtikz@transform@target@southwest{%
- tikz@scan@transform@one@point{#1}}%
- pgfextract@processtikz@transform@target@southeast{%
- tikz@scan@transform@one@point{#2}}%
- pgfextract@processtikz@transform@target@northeast{%
- tikz@scan@transform@one@point{#3}}%
- pgfextract@processtikz@transform@target@northwest{%
- tikz@scan@transform@one@point{#4}}%
- }
- }
- deftikzgridtransform{%
- pgfextract@processtikz@current@point{}%
- pgf@process{%
- pgfpointdiff{tikz@transform@source@southwest}%
- {tikz@transform@source@northeast}%
- }%
- pgf@xc=pgf@xpgf@yc=pgf@y%
- pgf@process{%
- pgfpointdiff{tikz@transform@source@southwest}{tikz@current@point}%
- }%
- pgfmathparse{pgf@x/pgf@xc}lettikz@tx=pgfmathresult%
- pgfmathparse{pgf@y/pgf@yc}lettikz@ty=pgfmathresult%
- %
- pgfpointlineattime{tikz@ty}{%
- pgfpointlineattime{tikz@tx}{tikz@transform@target@southwest}%
- {tikz@transform@target@southeast}}{%
- pgfpointlineattime{tikz@tx}{tikz@transform@target@northwest}%
- {tikz@transform@target@northeast}}%
- }
- % Initialize H matrix for perspective view
- pgfmathsetmacroH@tpp@aa{1}pgfmathsetmacroH@tpp@ab{0}pgfmathsetmacroH@tpp@ac{0}%pgfmathsetmacroH@tpp@ad{0}
- pgfmathsetmacroH@tpp@ba{0}pgfmathsetmacroH@tpp@bb{1}pgfmathsetmacroH@tpp@bc{0}%pgfmathsetmacroH@tpp@bd{0}
- pgfmathsetmacroH@tpp@ca{0}pgfmathsetmacroH@tpp@cb{0}pgfmathsetmacroH@tpp@cc{1}%pgfmathsetmacroH@tpp@cd{0}
- pgfmathsetmacroH@tpp@da{0}pgfmathsetmacroH@tpp@db{0}pgfmathsetmacroH@tpp@dc{0}%pgfmathsetmacroH@tpp@dd{1}
- %Initialize H matrix for main rotation
- pgfmathsetmacroH@rot@aa{1}pgfmathsetmacroH@rot@ab{0}pgfmathsetmacroH@rot@ac{0}%pgfmathsetmacroH@rot@ad{0}
- pgfmathsetmacroH@rot@ba{0}pgfmathsetmacroH@rot@bb{1}pgfmathsetmacroH@rot@bc{0}%pgfmathsetmacroH@rot@bd{0}
- pgfmathsetmacroH@rot@ca{0}pgfmathsetmacroH@rot@cb{0}pgfmathsetmacroH@rot@cc{1}%pgfmathsetmacroH@rot@cd{0}
- %pgfmathsetmacroH@rot@da{0}pgfmathsetmacroH@rot@db{0}pgfmathsetmacroH@rot@dc{0}pgfmathsetmacroH@rot@dd{1}
- pgfkeys{
- /three point perspective/.cd,
- p/.code args={(#1,#2,#3)}{
- pgfmathparse{int(round(#1))}
- ifnumpgfmathresult=0else
- pgfmathsetmacroH@tpp@ba{#2/#1}
- pgfmathsetmacroH@tpp@ca{#3/#1}
- pgfmathsetmacroH@tpp@da{ 1/#1}
- coordinate (vp-p) at (#1,#2,#3);
- fi
- },
- q/.code args={(#1,#2,#3)}{
- pgfmathparse{int(round(#2))}
- ifnumpgfmathresult=0else
- pgfmathsetmacroH@tpp@ab{#1/#2}
- pgfmathsetmacroH@tpp@cb{#3/#2}
- pgfmathsetmacroH@tpp@db{ 1/#2}
- coordinate (vp-q) at (#1,#2,#3);
- fi
- },
- r/.code args={(#1,#2,#3)}{
- pgfmathparse{int(round(#3))}
- ifnumpgfmathresult=0else
- pgfmathsetmacroH@tpp@ac{#1/#3}
- pgfmathsetmacroH@tpp@bc{#2/#3}
- pgfmathsetmacroH@tpp@dc{ 1/#3}
- coordinate (vp-r) at (#1,#2,#3);
- fi
- },
- coordinate/.code args={#1,#2,#3}{
- pgfmathsetmacrotpp@x{#1} %<- Max' fix
- pgfmathsetmacrotpp@y{#2}
- pgfmathsetmacrotpp@z{#3}
- },
- }
- tikzset{
- view/.code 2 args={
- pgfmathsetmacrorot@main@theta{#1}
- pgfmathsetmacrorot@main@phi{#2}
- % Row 1
- pgfmathsetmacroH@rot@aa{cos(rot@main@phi)}
- pgfmathsetmacroH@rot@ab{sin(rot@main@phi)}
- pgfmathsetmacroH@rot@ac{0}
- % Row 2
- pgfmathsetmacroH@rot@ba{-cos(rot@main@theta)*sin(rot@main@phi)}
- pgfmathsetmacroH@rot@bb{cos(rot@main@phi)*cos(rot@main@theta)}
- pgfmathsetmacroH@rot@bc{sin(rot@main@theta)}
- % Row 3
- pgfmathsetmacroH@m@ca{sin(rot@main@phi)*sin(rot@main@theta)}
- pgfmathsetmacroH@m@cb{-cos(rot@main@phi)*sin(rot@main@theta)}
- pgfmathsetmacroH@m@cc{cos(rot@main@theta)}
- % Set vector values
- pgfmathsetmacrovec@x@x{H@rot@aa}
- pgfmathsetmacrovec@y@x{H@rot@ab}
- pgfmathsetmacrovec@z@x{H@rot@ac}
- pgfmathsetmacrovec@x@y{H@rot@ba}
- pgfmathsetmacrovec@y@y{H@rot@bb}
- pgfmathsetmacrovec@z@y{H@rot@bc}
- % Set pgf vectors
- pgfsetxvec{pgfpoint{vec@x@x cm}{vec@x@y cm}}
- pgfsetyvec{pgfpoint{vec@y@x cm}{vec@y@y cm}}
- pgfsetzvec{pgfpoint{vec@z@x cm}{vec@z@y cm}}
- },
- }
- tikzset{
- perspective/.code={pgfkeys{/three point perspective/.cd,#1}},
- perspective/.default={p={(15,0,0)},q={(0,15,0)},r={(0,0,50)}},
- }
- tikzdeclarecoordinatesystem{three point perspective}{
- pgfkeys{/three point perspective/.cd,coordinate={#1}}
- pgfmathsetmacrotemp@p@w{H@tpp@da*tpp@x + H@tpp@db*tpp@y + H@tpp@dc*tpp@z + 1}
- pgfmathsetmacrotemp@p@x{(H@tpp@aa*tpp@x + H@tpp@ab*tpp@y + H@tpp@ac*tpp@z)/temp@p@w}
- pgfmathsetmacrotemp@p@y{(H@tpp@ba*tpp@x + H@tpp@bb*tpp@y + H@tpp@bc*tpp@z)/temp@p@w}
- pgfmathsetmacrotemp@p@z{(H@tpp@ca*tpp@x + H@tpp@cb*tpp@y + H@tpp@cc*tpp@z)/temp@p@w}
- pgfpointxyz{temp@p@x}{temp@p@y}{temp@p@z}
- }
- tikzaliascoordinatesystem{tpp}{three point perspective}
- makeatother
- begin{document}
- tdplotsetmaincoords{80}{-20}
- begin{tikzpicture}[scale=pi,%tdplot_main_coords
- view={tdplotmaintheta}{tdplotmainphi},
- perspective={
- p = {(5,0,0.5)},
- q = {(0,4,0.5)},
- },
- declare function={potential(x)=-0.0314*pow(abs(x),2);}
- ]
- draw[thick] plot[variable=x,domain=0:360,samples=37,smooth]
- (tpp cs:{cos(x)},{sin(x)},0);
- pgfmathsetmacro{Nion}{40}
- pgfmathsetmacro{Dist}{360/Nion}
- pgfmathsetmacro{xmin}{1}
- pgfmathsetmacro{xmax}{Dist-xmin}
- draw[-latex] (tpp cs:0,-1,0) -- (tpp cs:0,-1,{1.2*potential(xmin-Dist/2)})
- node[right]{$V$};
- draw[-latex] plot[variable=x,domain=0:Dist,samples={Dist+1},smooth]
- (tpp cs:{cos(-90+x)},{sin(-90+x)},{-0.2*potential(xmin-Dist/2)});
- node[anchor=south] at (tpp cs:{cos(-90+Dist/2)},{sin(-90+Dist/2)},{-0.22*potential(xmin-Dist/2)})
- {$x$};
- foreach index in {1,...,Nion}
- {draw plot[variable=x,domain=xmin:xmax,samples={Dist+1},smooth]
- (tpp
- cs:{cos(x+index*Dist)},{sin(x+index*Dist)},{potential(x-Dist/2)});
- fill (tpp cs:{cos(index*Dist)},{sin(index*Dist)},0) circle(1pt);
- }
- end{tikzpicture}
- end{document}
- usetikzlibrary{backgrounds}
- begin{document}
- tdplotsetmaincoords{80}{-20}
- begin{tikzpicture}[scale=pi,%tdplot_main_coords
- view={tdplotmaintheta}{tdplotmainphi},
- perspective={
- p = {(5,0,0.5)},
- q = {(0,4,0.5)},
- },
- declare function={potential(x)=ifthenelse(abs(x)<Dist/4,0,-1);}
- ]
- draw[thick] plot[variable=x,domain=0:360,samples=37,smooth]
- (tpp cs:{cos(x)},{sin(x)},0);
- pgfmathsetmacro{Nion}{40}
- pgfmathsetmacro{Dist}{360/Nion}
- pgfmathsetmacro{xmin}{0}
- pgfmathsetmacro{xmax}{Dist-xmin}
- draw[-latex] (tpp cs:0,-1,0) -- (tpp cs:0,-1,{1.2*potential(xmin-Dist/2)})
- node[right]{$V$};
- draw[-latex] plot[variable=x,domain=0:Dist,samples={Dist+1},smooth]
- (tpp cs:{cos(-90+x)},{sin(-90+x)},{-0.2*potential(xmin-Dist/2)});
- node[anchor=south] at (tpp cs:{cos(-90+Dist/2)},{sin(-90+Dist/2)},{-0.22*potential(xmin-Dist/2)})
- {$x$};
- foreach index in {1,...,Nion}
- {begin{scope}[on background layer]
- draw[thick,blue] plot[variable=x,domain=xmin:xmax,samples={29}]
- (tpp
- cs:{cos(x+index*Dist)},{sin(x+index*Dist)},{potential(x-Dist/2)});
- end{scope}
- fill (tpp cs:{cos(index*Dist)},{sin(index*Dist)},0) circle(1pt);
- }
- end{tikzpicture}
- end{document}
Add Comment
Please, Sign In to add comment