5

I found a nice solution to draw explosions using Tikz (TiKZ: "hand-drawn" explosion)

However, I need only the superior half part of this shape. How do I crop out the bottom part?

Here is some code of my drawing, The objective is to gat an explosion at the bottom of the well.

\begin{tikzpicture}
%-> DRAW THE EXPLOSION
\node[starburst, draw, minimum width=0.3cm, minimum height=0.4cm, red, fill=orange] at (0,0) {};

%-> DEFINE THE FUNCTIONS OF THE PARABOLAS
\def\v0{7.5}
\def\fcn#1{tan(#1)*abs(\x) - 9.8*(\x)^2/(2*(\v0*cos(#1))^2)}
\def\Fcn{(\v0)^2/19.6 - 9.8*(\x)^2/(2*(\v0)^2)}
\def\xrange#1{(\v0)^2*sin(2*#1)/9.8}

%-> DRAW THE WELL
\def\well#1{
    \foreach \x in {#1}
        \fill[gray!25,opacity=0.25]
            ({-#1},{\Fcn}) rectangle({-\xrange{45}},0)
            ({#1},{\Fcn}) rectangle({\xrange{45}},0)
            ;
    \foreach \x in {#1}
        \draw[gray]
            ({-#1},0)--
                ({-#1},{\Fcn})--
                ({-\xrange{45}},{\Fcn})
            ({#1},0)--
                ({#1},{\Fcn})--
                ({\xrange{45}},{\Fcn})
            ;
}
\def\wellrad{2}
\well{\wellrad}

%-> DRAW THE PARABOLAS
\def\myplot#1#2{
    \draw[samples=100,domain=-\xrange{#1}:\xrange{#1},#2]
        plot (\x, {\fcn{#1}});
}
\myplot{75}{dotted,gray}
\myplot{60}{dotted,gray}
\myplot{45}{dash dot,gray}
\myplot{30}{dashed,gray}
\myplot{15}{dashed,gray}
\draw[thick,domain=-\xrange{45}:\xrange{45}]
    plot (\x, {\Fcn});

%-> DRAW THE AXIS
%... horizontal
\draw[->, very thick]
    ({-\xrange{45}-0.5},0)--
        ({\xrange{45}+0.5},0) node[below]{$x$}
    ;
%... vertical
\draw[->, very thick]
    (0,0)--
        (0,{\xrange{45}/2+0.5}) node[left]{$y$}
    ;

%-> DRAW THE NODES
\draw
    ({-\wellrad},0) node[below]{$-R$}
    (0,0) node[below]{0}
    ({\wellrad},0) node[below]{$R$}
    ;
\foreach \x in {\wellrad}
    \draw[<->, very thick]
    ({-\xrange{45}-0.2},0)--
        ({-\xrange{45}-0.2},{\Fcn}) node[midway, left]{$h$}
    ;
\end{tikzpicture}
  • 1
    check out TikZ's crop environment. – A.Ellett Oct 13 '18 at 18:26
  • 2
    @marmot Indeed I meant clip, not crop. Sigh. Thank you for the correction. – A.Ellett Oct 13 '18 at 18:38
5

You could just clip the star burst.

\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{shapes}
\begin{document}
\begin{tikzpicture}
%-> DRAW THE EXPLOSION
\begin{scope}
\clip (-2,0) rectangle (2,2);
\node[starburst, draw, minimum width=0.3cm, minimum height=0.4cm, red, fill=orange] at (0,0) {};
\end{scope}

%-> DEFINE THE FUNCTIONS OF THE PARABOLAS
\def\v0{7.5}
\def\fcn#1{tan(#1)*abs(\x) - 9.8*(\x)^2/(2*(\v0*cos(#1))^2)}
\def\Fcn{(\v0)^2/19.6 - 9.8*(\x)^2/(2*(\v0)^2)}
\def\xrange#1{(\v0)^2*sin(2*#1)/9.8}

%-> DRAW THE WELL
\def\well#1{
    \foreach \x in {#1}
        \fill[gray!25,opacity=0.25]
            ({-#1},{\Fcn}) rectangle({-\xrange{45}},0)
            ({#1},{\Fcn}) rectangle({\xrange{45}},0)
            ;
    \foreach \x in {#1}
        \draw[gray]
            ({-#1},0)--
                ({-#1},{\Fcn})--
                ({-\xrange{45}},{\Fcn})
            ({#1},0)--
                ({#1},{\Fcn})--
                ({\xrange{45}},{\Fcn})
            ;
}
\def\wellrad{2}
\well{\wellrad}

%-> DRAW THE PARABOLAS
\def\myplot#1#2{
    \draw[samples=100,domain=-\xrange{#1}:\xrange{#1},#2]
        plot (\x, {\fcn{#1}});
}
\myplot{75}{dotted,gray}
\myplot{60}{dotted,gray}
\myplot{45}{dash dot,gray}
\myplot{30}{dashed,gray}
\myplot{15}{dashed,gray}
\draw[thick,domain=-\xrange{45}:\xrange{45}]
    plot (\x, {\Fcn});

%-> DRAW THE AXIS
%... horizontal
\draw[->, very thick]
    ({-\xrange{45}-0.5},0)--
        ({\xrange{45}+0.5},0) node[below]{$x$}
    ;
%... vertical
\draw[->, very thick]
    (0,0)--
        (0,{\xrange{45}/2+0.5}) node[left]{$y$}
    ;

%-> DRAW THE NODES
\draw
    ({-\wellrad},0) node[below]{$-R$}
    (0,0) node[below]{0}
    ({\wellrad},0) node[below]{$R$}
    ;
\foreach \x in {\wellrad}
    \draw[<->, very thick]
    ({-\xrange{45}-0.2},0)--
        ({-\xrange{45}-0.2},{\Fcn}) node[midway, left]{$h$}
    ;
\end{tikzpicture}
\end{document}

enter image description here

  • Hi, @marmot. Thank you for the response. I thought about drawing a white filled rectangle from (1,-1) to (1,0) after drawing the explosion shape. However, this work around generates extra vertical space on my figure, which is undesirable. Does this clipping also create extra space? Sorry for my dummy question. I am new at Tiks. – Brasil Oct 13 '18 at 18:41
  • 1
    @Brasil AFAIK clipping does not create extra space. Note that in this application you are absolutely safe because the clipped region is fully contained in the plot. BTW, you can always adjust the bounding box with the \path[use as bounding box] ... syntax, but this is not needed here. – user121799 Oct 13 '18 at 18:44
  • great! It worked perfectly! One thing more: can you explain the role of the scope environment, please? Thank you! – Brasil Oct 13 '18 at 18:46
  • 1
    @Brasil This just means that the clip affects everything within the scope, but not the things outside the scope. If you drop the scope, most of the plot will get clipped away, too. – user121799 Oct 13 '18 at 18:48

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.