12

My apologies in advance if you feel that this question is more about drawing instead of being technical.

The following diagram is what I want to replicate in Latex: desired output

I believe I have done most of the work, except for the bullet. The bullet has a round tip, which I am finding it hard to draw. The red lines are the sides of the bullet that I want to connect with the tip.

Could anyone suggest how to go from here?

What I have so far

\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{shapes.misc}
\usetikzlibrary{arrows}
\usepackage{mathtools}
\usepackage{pgfplots}
\usepackage{amsmath}
\begin{document}
\tikzset{cross/.style={cross out, draw=black, fill=none, minimum size=5*(#1-\pgflinewidth), inner sep=0pt, outer sep=0pt}, cross/.default={2pt}}
\text{}\\
\begin{tikzpicture}[x=0.5cm,y=0.5cm,z=0.3cm,>=stealth,scale=0.8]
% The axes
\draw[ultra thick,->] (xyz cs:x=-18.5,y=+2) -- (xyz cs:x=18.5,y=-2);
\draw[ultra thick,->] (xyz cs:y=-18.5) -- (xyz cs:y=18.5);
%\draw[ultra thick,dashed,->] (xyz cs:x=13,z=+10.5) -- (xyz cs:x=-13,z=-10.5);
\draw[ultra thick,dashed,opacity=0.4] (xyz cs:x=0,z=0) -- (xyz cs:x=9.2,z=+7.3);
\draw[ultra thick,dashed] (xyz cs:x=9.2,z=7.3) -- (xyz cs:x=13,z=+10.5);
\draw[ultra thick,dashed,->] (xyz cs:x=0,z=0) -- (xyz cs:x=-13,z=-10.5);
%%
%rectangle
\draw[draw=none,ultra thick,fill=gray!50,opacity=0.5]
(xyz cs:x=-12,y=+12)
-- (xyz cs:x=+12,y=9.5)
-- (xyz cs:x=+12,y=-12.5)
-- (xyz cs:x=-12,y=-10)
-- (xyz cs:x=-12,y=+12);
%
%Thickness of the sample
\draw[draw=none,ultra thick,fill=gray!50,opacity=0.3]
(xyz cs:x=-12,y=+12)
-- (xyz cs:x=-10.5,y=12.5)
-- (xyz cs:x=+13.5-0.25,y=10)
-- (xyz cs:x=+12,y=9.5)
%-- (xyz cs:x=-12,y=+12)
;
%
\draw[draw=none,ultra thick,fill=gray!90,opacity=0.5]
%(xyz cs:x=12,y=9.5)
(xyz cs:x=+13.5-0.05,y=+10+0.02)
-- (xyz cs:x=+13.5-0.051,y=-12)
%-- (xyz cs:x=+12.5,y=+9.5-22+0.5)
-- (xyz cs:x=+12,y=-12.5)
-- (xyz cs:x=+12,y=9.5)
;
%\draw[fill=black](xyz cs:x=0,y=0,z=0) circle (3pt);
%draw a cross   
\draw[ultra thick] (xyz cs:x=-0.75,y=+0.75) -- (xyz cs:x=+0.75,y=-0.75);
\draw[ultra thick] (xyz cs:x=-0.75,y=-0.75) -- (xyz cs:x=+0.75,y=+0.75);
%
%Labels
\node [below,scale=2] at (xyz cs:x=+1.5,y=-1) {$O$};
\node [below,scale=2] at (xyz cs:x=+18,y=-2.3) {$x$};
\node [above,scale=2] at (xyz cs:y=+18.5) {$y$};
\node [below,scale=2] at (xyz cs:z=-11,x=-12) {$z$};
%
\node [below,scale=2] at (xyz cs:x=-30,z=27) {\text{Sample}};
%
%Bullet
\draw[draw=none,fill=gray!50,opacity=0.5] (xyz cs:x=-14,y=-4.5) circle [x radius=5.5mm, y radius=7mm];
\draw[red] (xyz cs:x=-14,y=-3.12) -- (xyz cs:x=-11,y=-2.12);
\draw[red] (xyz cs:x=-14,y=-3.12-2.8) -- (xyz cs:x=-9.5,y=-4.49);
%\draw[blue] (xyz cs:x=-11,y=-2.12) parabola (xyz cs:x=-9.5,y=-4.49);
\end{tikzpicture}
\end{document}

Thank you!

  • 3
    I guess the biggest improvement will be achieved by switching to tikz-3dplot and using a real orthographic projection. – marmot Oct 24 '18 at 18:50
13

Here is a proposal. I translated your picture to tikz-3dplots which makes it IMHO much easier to draw such things. In particular, you have an orthographic projection for free.

\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{amsmath}
\usepackage{tikz-3dplot}
\usetikzlibrary{3d,shadings,calc,arrows.meta}
% small fix for canvas is xy plane at z % https://tex.stackexchange.com/a/48776/121799
\makeatletter
\tikzoption{canvas is xy plane at z}[]{%
    \def\tikz@plane@origin{\pgfpointxyz{0}{0}{#1}}%
    \def\tikz@plane@x{\pgfpointxyz{1}{0}{#1}}%
    \def\tikz@plane@y{\pgfpointxyz{0}{1}{#1}}%
    \tikz@canvas@is@plane}
\makeatother
\begin{document}
\tdplotsetmaincoords{70}{-230}
\tdplotsetrotatedcoords{0}{90}{90}
\tikzset{cross/.style={cross out, draw=black, fill=none, minimum size=5*(#1-\pgflinewidth), inner sep=0pt, outer sep=0pt}, cross/.default={2pt}}
\begin{tikzpicture}[font=\sffamily]
\begin{scope}[tdplot_rotated_coords,>=stealth,scale=0.6,local bounding box=3d]
% z axis in background
\draw[ultra thick,dotted] (0,0,-24) -- (0,0,0) coordinate (O);
%rectangle
\fill[gray!50,opacity=0.5]
(12,12,0) coordinate(tr) -- 
(12,-12,0) coordinate(br) -- 
(-12,-12,0) coordinate(bl) -- 
(-12,12,0) coordinate(tl) -- cycle;
\fill[gray!90,opacity=0.5]
(tr) -- ++(0,0,-2) -- ++(0,-24,0) -- (br) -- cycle;
\fill[gray!50,opacity=0.3]
(tr) -- ++(0,0,-2) -- ++(-24,0,0) -- (tl) -- cycle;
% The axes
\draw[ultra thick,->] (-18.5,0,0) -- (18.5,0,0) node[below,scale=2]{$x$};
\draw[ultra thick,->] (xyz cs:y=-18.5) -- (xyz cs:y=18.5) node[above,scale=2]{$y$};
\draw[ultra thick,dotted,->] (0,0,0) --(0,0,10);
%draw a cross   
\draw[ultra thick] (xyz cs:x=-0.75,y=+0.75) -- (xyz cs:x=+0.75,y=-0.75);
\draw[ultra thick] (xyz cs:x=-0.75,y=-0.75) -- (xyz cs:x=+0.75,y=+0.75);
%
%Labels
\node [below,scale=2] at (xyz cs:x=+1.5,y=-1) {$O$};
%
%Bullet
\begin{scope}[canvas is xy plane at z=10]
\coordinate (c1) at (120:1);
\coordinate (c2) at (-60:1);
\end{scope}
\begin{scope}[canvas is xy plane at z=16]
\fill[gray!50,opacity=0.5] circle (1);
\coordinate (b1) at (120:1);
\coordinate (b2) at (-60:1);
\coordinate (z0) at (0,0);
\shade let \p1=($(c1)-(b1)$),\n1={atan2(\y1,\x1)} in
[top color=black!60,bottom color=black,middle color=gray!30,
shading angle=\n1] (b1) -- (c1) to[out=30,in=30,looseness=3] (c2) -- (b2)
arc(-60:120:1);
\end{scope}
\draw[ultra thick,dotted,->] (z0) -- (0,0,24) node[below,scale=2]{$z$};
\coordinate (a1) at (-8,8,0);
\end{scope}
\begin{scope}[every node/.append style={scale=2},shorten >=2mm]
\node[anchor=north west] (sample) at (3d.north west) {sample};
\node[anchor=south west] (bullet) at (3d.south west) {bullet};
\node[anchor=south east] (origin) at (3d.south east) {origin};
\draw [-{Stealth[length=2mm]}] (sample)-- (a1);
\draw [-{Stealth[length=2mm]}] (bullet)-- (z0);
\draw [-{Stealth[length=2mm]}] (origin)-- (O);
\end{scope}
\end{tikzpicture}
\end{document}

enter image description here

And I almost forgot the animation. (Some details have also changed, the bullet is a bit transparent etc.)

\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{amsmath}
\usepackage{tikz-3dplot}
\usetikzlibrary{3d,shadings,calc,arrows.meta}
% small fix for canvas is xy plane at z % https://tex.stackexchange.com/a/48776/121799
\makeatletter
\tikzoption{canvas is xy plane at z}[]{%
    \def\tikz@plane@origin{\pgfpointxyz{0}{0}{#1}}%
    \def\tikz@plane@x{\pgfpointxyz{1}{0}{#1}}%
    \def\tikz@plane@y{\pgfpointxyz{0}{1}{#1}}%
    \tikz@canvas@is@plane}
\makeatother
\begin{document}
\foreach \X in {0,...,18}
{
\pgfmathsetmacro{\zbullet}{1+18-\X}
\tdplotsetmaincoords{70}{-250+2*\X}
\tdplotsetrotatedcoords{0}{90}{90}
\begin{tikzpicture}[font=\sffamily]
\draw (-15,-12) rectangle (15,12);
\begin{scope}[tdplot_rotated_coords,>=stealth,scale=0.6,local bounding box=3d]
% z axis in background
\draw[ultra thick,dotted] (0,0,-24) -- (0,0,0) coordinate (O);
%rectangle
\fill[gray!50,opacity=0.5]
(12,12,0) coordinate(tr) -- 
(12,-12,0) coordinate(br) -- 
(-12,-12,0) coordinate(bl) -- 
(-12,12,0) coordinate(tl) -- cycle;
\fill[gray!90,opacity=0.5]
(tr) -- ++(0,0,-2) -- ++(0,-24,0) -- (br) -- cycle;
\fill[gray!50,opacity=0.3]
(tr) -- ++(0,0,-2) -- ++(-24,0,0) -- (tl) -- cycle;
% The axes
\draw[ultra thick,->] (-18.5,0,0) -- (18.5,0,0) node[below,scale=2]{$x$};
\draw[ultra thick,->] (0,-18.5,0) -- (0,18.5,0) node[above,scale=2]{$y$};
\draw[ultra thick,dotted] (O) --(0,0,\zbullet+6);
%draw a cross   
\begin{scope}[canvas is xy plane at z=0]
\draw[ultra thick] (-0.75,0.75) -- (0.75,-0.75);
\draw[ultra thick] (-0.75,-0.75) -- (0.75,0.75);
\end{scope}
%
%Labels
\node [below,scale=2] at (xyz cs:x=+1.5,y=-1) {$O$};
%
%Bullet
\begin{scope}[canvas is xy plane at z=\zbullet]
\coordinate (c1) at (120:1);
\coordinate (c2) at (-60:1);
\end{scope}
\begin{scope}[canvas is xy plane at z=\zbullet+6,opacity=0.8]
\fill[gray!50] circle (1);
\coordinate (b1) at (120:1);
\coordinate (b2) at (-60:1);
\coordinate (z0) at (0,0);
\shade let \p1=($(c1)-(b1)$),\n1={atan2(\y1,\x1)} in
[top color=black!60,bottom color=black,middle color=gray!30,
shading angle=\n1] (b1) -- (c1) to[out=\n1,in=\n1,looseness=3] (c2) -- (b2)
arc(-60:120:1);
\end{scope}
\draw[ultra thick,dotted,->] (z0) -- (0,0,30) node[below,scale=2]{$z$};
\coordinate (a1) at (-8,8,0);
\end{scope}
\begin{scope}[every node/.append style={scale=2},shorten >=2mm]
\node[anchor=north west] (sample) at (3d.north west) {sample};
\node[anchor=south west] (bullet) at (3d.south west) {bullet};
\node[anchor=south east] (origin) at (3d.south east) {origin};
\draw [-{Stealth[length=2mm]}] (sample)-- (a1);
\draw [-{Stealth[length=2mm]}] (bullet)-- (z0);
\draw [-{Stealth[length=2mm]}] (origin)-- (O);
\end{scope}
\end{tikzpicture}
}
\end{document}

enter image description here

  • Another question I have is: how would you reduce the length of the bullet? – Will Kim Oct 25 '18 at 12:31
  • Just saw the animation bit and wow, this is amazing! Do you write books and latex and publish them? – Will Kim Oct 25 '18 at 12:41
  • @WillKim No, I do not write books. In fact, I just started learning TikZ one year ago. But it is a ver nice tool, so it allows one to do many nice things with little effort. Glad you like it! ;-) – marmot Oct 25 '18 at 14:20
  • Wow, how come are you so knowledgeable? Thanks for helping me with this one. It’s a work of art! – Will Kim Oct 25 '18 at 14:22
  • 1
    For the record: Jake's patch is now incorporated in v3.1 of TikZ. – Stefan Pinnow Jan 15 at 19:03

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.