6

How to add the typical grid cells

enter image description here

(image modified from https://en.wikipedia.org/wiki/Death_Star) to the following sketch of the death star?

This is what I have so far

\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}

enter image description here

However the rectangle does not follow the shape of the grid and also does not have the shading.

4
  • 2
    There are many questions already about drawing lines on a sphere. You need to explain what you mean, and not just write typical grid lines. tex.stackexchange.com/questions/269959/… tex.stackexchange.com/questions/226507/… Commented May 4, 2019 at 12:29
  • @hpekristiansen Thanks for the links, however I don't want to draw lines, I'd like to add the rectangular grid structures. I attached an image, maybe this will make it clearer.
    – Han Solo
    Commented May 4, 2019 at 18:21
  • You may be interested in this thread which explains how you can modify the shading.
    – user121799
    Commented May 4, 2019 at 18:25
  • @marmot Thank you very much for the link, this looks very helpful! I will read it carefully!
    – Han Solo
    Commented May 4, 2019 at 18:27

1 Answer 1

10

Here is a quick proposal based on percusse's nice answer.

\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}

enter image description here

Some pattern for CarLaTeX. There is a huge room for improvements. The pattern is drawn using sphere segments.

\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}

enter image description here

6
  • Is the hole a real hole of the sphere or it is an ellipse?
    – manooooh
    Commented May 4, 2019 at 19:05
  • 1
    @manooooh It is a circle on the surface of the larger sphere subjected to orthographic projections.
    – user121799
    Commented May 4, 2019 at 19:06
  • 2
    +1 but the rectangles?
    – CarLaTeX
    Commented May 4, 2019 at 20:07
  • @marmot They are already gorgeous, in my opinion!
    – CarLaTeX
    Commented May 5, 2019 at 2:56
  • @CarLaTeX At least the timing for the question was very well chosen. May the fourth be with you!
    – user121799
    Commented May 5, 2019 at 3:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .