画死星

画死星

如何添加典型网格单元

在此处输入图片描述

(图片修改自https://en.wikipedia.org/wiki/Death_Star)到下面的死星草图?

这是我目前所拥有的

\documentclass{standalone}

\usepackage{tikz}

\begin{document}

\begin{tikzpicture}
\fill[ball color=gray!10!white,  shading=ball] (0,0) circle (1);
\shade[outer color=gray!10!white, inner color=gray,draw=gray!50!white] (-0.3,0.3) circle (0.35);

\fill[gray!50!white] (0,0) rectangle (0.2,-0.3);
\end{tikzpicture}

\end{document}

在此处输入图片描述

然而,矩形并不符合网格的形状,也没有阴影。

答案1

以下是基于percusse 的精彩回答

\documentclass[border=5mm]{standalone}
\usepackage{tikz}
\pgfdeclarefunctionalshading{eightball}{\pgfpointorigin}{\pgfpoint{100bp}{100bp}}{}{
% Compute distance difference (horizontally weighted twice). (50bp,50bp) is the center
65 sub dup mul exch                %Change the coordinate to move vertically
40 sub dup mul 0.5 mul add sqrt   %Change the coordinate to move horizontally
% In MATLAB notation : d=distance diff
% x=1.003^(-d^2)
dup mul neg 1.003 exch exp
% x is the only variable in the stack now but we need 3 values at the top of the stack
% so we duplicate these values putting new values in the stack.
dup % Duplicates with the current value and pushes the stack down (value of green)
dup % Duplicates with the current value and pushes the stack down (value of blue)
}
\makeatletter % https://tex.stackexchange.com/a/38995/121799
\tikzset{
  use path/.code={\pgfsyssoftpath@setcurrentpath{#1}}
}
\makeatother
\usepackage{tikz-3dplot} 
\begin{document}
\begin{tikzpicture}
\shade[shading=eightball,transform canvas={rotate=80,xscale=-1}] (0,0) circle (5cm);
\tdplotsetmaincoords{00}{00}
\pgfmathsetmacro{\mybeta}{acos(0.7)}
\pgfmathsetmacro{\myalpha}{acos(-0.3)/sin(\mybeta)}
\tdplotsetrotatedcoords{\myalpha}{\mybeta}{00}
\begin{scope}[tdplot_rotated_coords,canvas is xy plane at z=4]
 \draw[thick,save path=\tmPath] circle[radius=1.8cm];
\end{scope}
\clip[use path=\tmPath];
\shade[tdplot_screen_coords,shading=eightball,transform
canvas={rotate=-100,xscale=-1}] (-75:2.5) circle
(2.5cm);
\end{tikzpicture}
\end{document}

在此处输入图片描述

CarLaTeX 的一些图案。有很大的改进空间。图案是使用以下方法绘制的球面部分

\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{fadings,decorations.text}
\pgfdeclarefunctionalshading{eightball}{\pgfpointorigin}{\pgfpoint{100bp}{100bp}}{}{
% Compute distance difference (horizontally weighted twice). (50bp,50bp) is the center
65 sub dup mul exch                %Change the coordinate to move vertically
40 sub dup mul 0.5 mul add sqrt   %Change the coordinate to move horizontally
% In MATLAB notation : d=distance diff
% x=1.003^(-d^2)
dup mul neg 1.003 exch exp
% x is the only variable in the stack now but we need 3 values at the top of the stack
% so we duplicate these values putting new values in the stack.
dup % Duplicates with the current value and pushes the stack down (value of green)
dup % Duplicates with the current value and pushes the stack down (value of blue)
}
\makeatletter % https://tex.stackexchange.com/a/38995/121799
\tikzset{
  use path/.code={\pgfsyssoftpath@setcurrentpath{#1}}
}
\makeatother
\tikzfading[name=fade right,left color=transparent!0,right color=transparent!100]
\usepackage{tikz-3dplot} 
\begin{document}
\begin{tikzpicture}[sphere segment/.style args={% from https://tex.stackexchange.com/a/482332/121799
 phi from #1 to #2 and theta from #3 to #4 and radius #5}{insert path={%
 plot[variable=\x,smooth,domain=#2:#1] 
 (xyz spherical cs:radius=#5,longitude=\x,latitude=#3)
 -- plot[variable=\x,smooth,domain=#3:#4] 
 (xyz spherical cs:radius=#5,longitude=#1,latitude=\x)
 --plot[variable=\x,smooth,domain=#1:#2] 
 (xyz spherical cs:radius=#5,longitude=\x,latitude=#4)
 -- plot[variable=\x,smooth,domain=#4:#3] 
 (xyz spherical cs:radius=#5,longitude=#2,latitude=\x)
 -- cycle}},death star/.cd,
 radius/.initial=5,inlay radius/.initial=1.8]
  \fill (-1.2*\pgfkeysvalueof{/tikz/death star/radius},
   -1.2*\pgfkeysvalueof{/tikz/death star/radius}) rectangle
   (1.2*\pgfkeysvalueof{/tikz/death star/radius},
   1.4*\pgfkeysvalueof{/tikz/death star/radius});
  \path[decorate,decoration={raise=1ex,text along path,text
   align=center,text color=yellow,text={|\Huge\sffamily\bfseries|May the 4th be with you!}}] (180:1.1*\pgfkeysvalueof{/tikz/death star/radius}) 
   arc(180:0:1.1*\pgfkeysvalueof{/tikz/death star/radius});
  \shade[shading=eightball,transform canvas={rotate=80,xscale=-1},save
   path=\Sphere] (0,0) circle [radius=\pgfkeysvalueof{/tikz/death star/radius}*1cm];
  \tdplotsetmaincoords{0}{00}
  \pgfmathsetmacro{\mybeta}{acos(0.65)}
  \pgfmathsetmacro{\myalpha}{acos(-0.2)/sin(\mybeta)}
  \tdplotsetrotatedcoords{\myalpha}{\mybeta}{00}
  \begin{scope}[tdplot_rotated_coords,canvas is xy plane at
      z={sqrt(pow(\pgfkeysvalueof{/tikz/death star/radius},2)
      -pow(\pgfkeysvalueof{/tikz/death star/inlay radius},2))}]
   \draw[thick,save path=\tmPath] 
    circle[radius=\pgfkeysvalueof{/tikz/death star/inlay radius}*1cm];
  \end{scope}
  \begin{scope}[x={(1cm,0)},y={(0,0)},z={(0,1cm)}]
   \pgfmathsetseed{2}
   \path[save path=\tmPathTwo] foreach \X [count=\XC] in {50,20,-40,-70} {
    foreach \Y [count=\YC,evaluate=\YC as \ZC using {int(3.3*rnd)}] 
    in {-65,-45,-25,-5,15,35,55} 
    {\ifodd\ZC
     [sphere segment=phi from {\Y} to {\Y+10} and theta from {\X} to {\X+20} and radius \pgfkeysvalueof{/tikz/death star/radius}]
    \fi}}
    [sphere segment=phi from {-90} to {90} and theta from {1} to {10} and radius \pgfkeysvalueof{/tikz/death star/radius},
    sphere segment=phi from {-90} to {90} and theta from {-1} to {-10} and radius \pgfkeysvalueof{/tikz/death star/radius}];
  \end{scope}
  \begin{scope}
   \clip[use path=\tmPathTwo];
   \shade[ball color=white,opacity=0.3,path fading=fade right] (0,0) circle[radius=\pgfkeysvalueof{/tikz/death star/radius}*1cm];
  \end{scope}
  \clip[use path=\tmPath];
  \shade[tdplot_screen_coords,shading=eightball,transform
   canvas={rotate=-100,xscale=-1}] (-55:2.85) circle (\pgfkeysvalueof{/tikz/death
   star/radius}*0.5cm);
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容