Guest User

Untitled

a guest
Sep 24th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.91 KB | None | 0 0
  1. documentclass[tikz,border=3.14mm]{standalone}
  2. usepackage{tikz-3dplot}
  3. usepgfmodule{nonlineartransformations}
  4. usepackage{mathtools}
  5. % Max magic
  6. makeatletter
  7. % the first part is not in use here
  8. deftikz@scan@transform@one@point#1{%
  9. tikz@scan@one@pointpgf@process#1%
  10. pgf@pos@transform{pgf@x}{pgf@y}}
  11. tikzset{%
  12. grid source opposite corners/.code args={#1and#2}{%
  13. pgfextract@processtikz@transform@source@southwest{%
  14. tikz@scan@transform@one@point{#1}}%
  15. pgfextract@processtikz@transform@source@northeast{%
  16. tikz@scan@transform@one@point{#2}}%
  17. },
  18. grid target corners/.code args={#1--#2--#3--#4}{%
  19. pgfextract@processtikz@transform@target@southwest{%
  20. tikz@scan@transform@one@point{#1}}%
  21. pgfextract@processtikz@transform@target@southeast{%
  22. tikz@scan@transform@one@point{#2}}%
  23. pgfextract@processtikz@transform@target@northeast{%
  24. tikz@scan@transform@one@point{#3}}%
  25. pgfextract@processtikz@transform@target@northwest{%
  26. tikz@scan@transform@one@point{#4}}%
  27. }
  28. }
  29.  
  30. deftikzgridtransform{%
  31. pgfextract@processtikz@current@point{}%
  32. pgf@process{%
  33. pgfpointdiff{tikz@transform@source@southwest}%
  34. {tikz@transform@source@northeast}%
  35. }%
  36. pgf@xc=pgf@xpgf@yc=pgf@y%
  37. pgf@process{%
  38. pgfpointdiff{tikz@transform@source@southwest}{tikz@current@point}%
  39. }%
  40. pgfmathparse{pgf@x/pgf@xc}lettikz@tx=pgfmathresult%
  41. pgfmathparse{pgf@y/pgf@yc}lettikz@ty=pgfmathresult%
  42. %
  43. pgfpointlineattime{tikz@ty}{%
  44. pgfpointlineattime{tikz@tx}{tikz@transform@target@southwest}%
  45. {tikz@transform@target@southeast}}{%
  46. pgfpointlineattime{tikz@tx}{tikz@transform@target@northwest}%
  47. {tikz@transform@target@northeast}}%
  48. }
  49.  
  50. % Initialize H matrix for perspective view
  51. pgfmathsetmacroH@tpp@aa{1}pgfmathsetmacroH@tpp@ab{0}pgfmathsetmacroH@tpp@ac{0}%pgfmathsetmacroH@tpp@ad{0}
  52. pgfmathsetmacroH@tpp@ba{0}pgfmathsetmacroH@tpp@bb{1}pgfmathsetmacroH@tpp@bc{0}%pgfmathsetmacroH@tpp@bd{0}
  53. pgfmathsetmacroH@tpp@ca{0}pgfmathsetmacroH@tpp@cb{0}pgfmathsetmacroH@tpp@cc{1}%pgfmathsetmacroH@tpp@cd{0}
  54. pgfmathsetmacroH@tpp@da{0}pgfmathsetmacroH@tpp@db{0}pgfmathsetmacroH@tpp@dc{0}%pgfmathsetmacroH@tpp@dd{1}
  55.  
  56. %Initialize H matrix for main rotation
  57. pgfmathsetmacroH@rot@aa{1}pgfmathsetmacroH@rot@ab{0}pgfmathsetmacroH@rot@ac{0}%pgfmathsetmacroH@rot@ad{0}
  58. pgfmathsetmacroH@rot@ba{0}pgfmathsetmacroH@rot@bb{1}pgfmathsetmacroH@rot@bc{0}%pgfmathsetmacroH@rot@bd{0}
  59. pgfmathsetmacroH@rot@ca{0}pgfmathsetmacroH@rot@cb{0}pgfmathsetmacroH@rot@cc{1}%pgfmathsetmacroH@rot@cd{0}
  60. %pgfmathsetmacroH@rot@da{0}pgfmathsetmacroH@rot@db{0}pgfmathsetmacroH@rot@dc{0}pgfmathsetmacroH@rot@dd{1}
  61.  
  62. pgfkeys{
  63. /three point perspective/.cd,
  64. p/.code args={(#1,#2,#3)}{
  65. pgfmathparse{int(round(#1))}
  66. ifnumpgfmathresult=0else
  67. pgfmathsetmacroH@tpp@ba{#2/#1}
  68. pgfmathsetmacroH@tpp@ca{#3/#1}
  69. pgfmathsetmacroH@tpp@da{ 1/#1}
  70. coordinate (vp-p) at (#1,#2,#3);
  71. fi
  72. },
  73. q/.code args={(#1,#2,#3)}{
  74. pgfmathparse{int(round(#2))}
  75. ifnumpgfmathresult=0else
  76. pgfmathsetmacroH@tpp@ab{#1/#2}
  77. pgfmathsetmacroH@tpp@cb{#3/#2}
  78. pgfmathsetmacroH@tpp@db{ 1/#2}
  79. coordinate (vp-q) at (#1,#2,#3);
  80. fi
  81. },
  82. r/.code args={(#1,#2,#3)}{
  83. pgfmathparse{int(round(#3))}
  84. ifnumpgfmathresult=0else
  85. pgfmathsetmacroH@tpp@ac{#1/#3}
  86. pgfmathsetmacroH@tpp@bc{#2/#3}
  87. pgfmathsetmacroH@tpp@dc{ 1/#3}
  88. coordinate (vp-r) at (#1,#2,#3);
  89. fi
  90. },
  91. coordinate/.code args={#1,#2,#3}{
  92. pgfmathsetmacrotpp@x{#1} %<- Max' fix
  93. pgfmathsetmacrotpp@y{#2}
  94. pgfmathsetmacrotpp@z{#3}
  95. },
  96. }
  97.  
  98. tikzset{
  99. view/.code 2 args={
  100. pgfmathsetmacrorot@main@theta{#1}
  101. pgfmathsetmacrorot@main@phi{#2}
  102. % Row 1
  103. pgfmathsetmacroH@rot@aa{cos(rot@main@phi)}
  104. pgfmathsetmacroH@rot@ab{sin(rot@main@phi)}
  105. pgfmathsetmacroH@rot@ac{0}
  106. % Row 2
  107. pgfmathsetmacroH@rot@ba{-cos(rot@main@theta)*sin(rot@main@phi)}
  108. pgfmathsetmacroH@rot@bb{cos(rot@main@phi)*cos(rot@main@theta)}
  109. pgfmathsetmacroH@rot@bc{sin(rot@main@theta)}
  110. % Row 3
  111. pgfmathsetmacroH@m@ca{sin(rot@main@phi)*sin(rot@main@theta)}
  112. pgfmathsetmacroH@m@cb{-cos(rot@main@phi)*sin(rot@main@theta)}
  113. pgfmathsetmacroH@m@cc{cos(rot@main@theta)}
  114. % Set vector values
  115. pgfmathsetmacrovec@x@x{H@rot@aa}
  116. pgfmathsetmacrovec@y@x{H@rot@ab}
  117. pgfmathsetmacrovec@z@x{H@rot@ac}
  118. pgfmathsetmacrovec@x@y{H@rot@ba}
  119. pgfmathsetmacrovec@y@y{H@rot@bb}
  120. pgfmathsetmacrovec@z@y{H@rot@bc}
  121. % Set pgf vectors
  122. pgfsetxvec{pgfpoint{vec@x@x cm}{vec@x@y cm}}
  123. pgfsetyvec{pgfpoint{vec@y@x cm}{vec@y@y cm}}
  124. pgfsetzvec{pgfpoint{vec@z@x cm}{vec@z@y cm}}
  125. },
  126. }
  127.  
  128. tikzset{
  129. perspective/.code={pgfkeys{/three point perspective/.cd,#1}},
  130. perspective/.default={p={(15,0,0)},q={(0,15,0)},r={(0,0,50)}},
  131. }
  132.  
  133. tikzdeclarecoordinatesystem{three point perspective}{
  134. pgfkeys{/three point perspective/.cd,coordinate={#1}}
  135. pgfmathsetmacrotemp@p@w{H@tpp@da*tpp@x + H@tpp@db*tpp@y + H@tpp@dc*tpp@z + 1}
  136. pgfmathsetmacrotemp@p@x{(H@tpp@aa*tpp@x + H@tpp@ab*tpp@y + H@tpp@ac*tpp@z)/temp@p@w}
  137. pgfmathsetmacrotemp@p@y{(H@tpp@ba*tpp@x + H@tpp@bb*tpp@y + H@tpp@bc*tpp@z)/temp@p@w}
  138. pgfmathsetmacrotemp@p@z{(H@tpp@ca*tpp@x + H@tpp@cb*tpp@y + H@tpp@cc*tpp@z)/temp@p@w}
  139. pgfpointxyz{temp@p@x}{temp@p@y}{temp@p@z}
  140. }
  141. tikzaliascoordinatesystem{tpp}{three point perspective}
  142.  
  143. makeatother
  144.  
  145.  
  146. begin{document}
  147. tdplotsetmaincoords{80}{-20}
  148. begin{tikzpicture}[scale=pi,%tdplot_main_coords
  149. view={tdplotmaintheta}{tdplotmainphi},
  150. perspective={
  151. p = {(5,0,0.5)},
  152. q = {(0,4,0.5)},
  153. },
  154. declare function={potential(x)=-0.0314*pow(abs(x),2);}
  155. ]
  156. draw[thick] plot[variable=x,domain=0:360,samples=37,smooth]
  157. (tpp cs:{cos(x)},{sin(x)},0);
  158. pgfmathsetmacro{Nion}{40}
  159. pgfmathsetmacro{Dist}{360/Nion}
  160. pgfmathsetmacro{xmin}{1}
  161. pgfmathsetmacro{xmax}{Dist-xmin}
  162. draw[-latex] (tpp cs:0,-1,0) -- (tpp cs:0,-1,{1.2*potential(xmin-Dist/2)})
  163. node[right]{$V$};
  164. draw[-latex] plot[variable=x,domain=0:Dist,samples={Dist+1},smooth]
  165. (tpp cs:{cos(-90+x)},{sin(-90+x)},{-0.2*potential(xmin-Dist/2)});
  166. node[anchor=south] at (tpp cs:{cos(-90+Dist/2)},{sin(-90+Dist/2)},{-0.22*potential(xmin-Dist/2)})
  167. {$x$};
  168. foreach index in {1,...,Nion}
  169. {draw plot[variable=x,domain=xmin:xmax,samples={Dist+1},smooth]
  170. (tpp
  171. cs:{cos(x+index*Dist)},{sin(x+index*Dist)},{potential(x-Dist/2)});
  172. fill (tpp cs:{cos(index*Dist)},{sin(index*Dist)},0) circle(1pt);
  173. }
  174. end{tikzpicture}
  175. end{document}
  176.  
  177. usetikzlibrary{backgrounds}
  178. begin{document}
  179. tdplotsetmaincoords{80}{-20}
  180. begin{tikzpicture}[scale=pi,%tdplot_main_coords
  181. view={tdplotmaintheta}{tdplotmainphi},
  182. perspective={
  183. p = {(5,0,0.5)},
  184. q = {(0,4,0.5)},
  185. },
  186. declare function={potential(x)=ifthenelse(abs(x)<Dist/4,0,-1);}
  187. ]
  188. draw[thick] plot[variable=x,domain=0:360,samples=37,smooth]
  189. (tpp cs:{cos(x)},{sin(x)},0);
  190. pgfmathsetmacro{Nion}{40}
  191. pgfmathsetmacro{Dist}{360/Nion}
  192. pgfmathsetmacro{xmin}{0}
  193. pgfmathsetmacro{xmax}{Dist-xmin}
  194. draw[-latex] (tpp cs:0,-1,0) -- (tpp cs:0,-1,{1.2*potential(xmin-Dist/2)})
  195. node[right]{$V$};
  196. draw[-latex] plot[variable=x,domain=0:Dist,samples={Dist+1},smooth]
  197. (tpp cs:{cos(-90+x)},{sin(-90+x)},{-0.2*potential(xmin-Dist/2)});
  198. node[anchor=south] at (tpp cs:{cos(-90+Dist/2)},{sin(-90+Dist/2)},{-0.22*potential(xmin-Dist/2)})
  199. {$x$};
  200. foreach index in {1,...,Nion}
  201. {begin{scope}[on background layer]
  202. draw[thick,blue] plot[variable=x,domain=xmin:xmax,samples={29}]
  203. (tpp
  204. cs:{cos(x+index*Dist)},{sin(x+index*Dist)},{potential(x-Dist/2)});
  205. end{scope}
  206. fill (tpp cs:{cos(index*Dist)},{sin(index*Dist)},0) circle(1pt);
  207. }
  208. end{tikzpicture}
  209. end{document}
Add Comment
Please, Sign In to add comment