Draw two boxes on a slanted plane in a mechanical illustration

One way to draw the two inclined boxes is to use a scope with a rotate applied:

enter image description here

Code:

\documentclass[border=1pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{patterns}

\begin{document}

\begin{tikzpicture}
\draw  (2,3) coordinate (A) 
    -- (8,0) coordinate (B)
    -- (2,0) coordinate (C) 
    -- cycle;
\fill[pattern=north west lines]
    (2,-1) rectangle(8,0);
    \draw(7,.2 5) node[left] {$\theta$};
    
\begin{scope}[rotate=atan((3-0)/(2-8))]
    \draw  [fill=cyan!40, densely dashed] ([shift={(-0.5,0)}]A) rectangle ++(1,0.5);
    \draw  [fill=red!20]                  ([shift={(-0.5,0)}]B) rectangle ++(1,0.5);
\end{scope}
\end{tikzpicture}
\end{document}

\documentclass[border = 5pt]{standalone}

\usepackage{tikz}
\usetikzlibrary{patterns, calc, quotes, angles}

\def\inc{25}

\begin{document}
\begin{tikzpicture}

  % incline
  \draw (0,0) coordinate(O) -- (180-\inc : 7) coordinate(A) |- coordinate (D) ($(O)+(0,-1)$) -- cycle;
  \draw[dashed] (O) -| coordinate (C) (A);
  \fill[pattern = north west lines] (D) rectangle (O);

  % measures
  \draw[|<->|] ($(A)+(-0.5, 0)$) -- ($(C)+(-0.5, 0)$) node[midway, left]{$h$};
  \pic["$\theta$", <->, draw, angle eccentricity = 1.2, angle radius = 1cm] {angle = A--O--C};


  % block
  \begin{scope}[rotate=180-\inc]
    \draw[shift={(A)}, dashed] ($(A)+(-0.4,0)$) rectangle ++ (0.8,-0.6);
    \draw (-0.4, 0) rectangle ++ (0.8,-0.6);
    \draw[-latex] (0.4, -1) -- (-0.4, -1) node[above, midway]{${\bf v}$};
  \end{scope}
\end{tikzpicture}
\end{document}

enter image description here

Plus a little animation

\documentclass[border = 5pt, tikz]{standalone}

\usepackage{tikz}
\usetikzlibrary{patterns, calc, quotes, angles}

\begin{document}

\foreach \inc in {60,58,...,20,22,24,...,60}
{
  \begin{tikzpicture}
    \useasboundingbox (-8, -1.5) rectangle (1, 6);

    % incline
    \draw (0,0) coordinate(O) -- (180-\inc : 7) coordinate(A) |- coordinate (D) ($(O)+(0,-1)$) -- cycle;
    \draw[dashed] (O) -| coordinate (C) (A);
    \fill[pattern = north west lines] (D) rectangle (O);

    % measures
    \draw[|<->|] ($(A)+(-0.5, 0)$) -- ($(C)+(-0.5, 0)$) node[midway, left]{$h$};
    \pic["$\theta$", <->, draw, angle eccentricity = 1.2, angle radius = 1cm] {angle = A--O--C};


    % block
    \begin{scope}[rotate=180-\inc]
      \draw[shift={(A)}, dashed] ($(A)+(-0.4,0)$) rectangle ++ (0.8,-0.6);
      \draw (-0.4, 0) rectangle ++ (0.8,-0.6);
      \draw[-latex] (0.4, -1) -- (-0.4, -1) node[above, midway]{${\bf v}$};
    \end{scope}
  \end{tikzpicture}
}
\end{document}

enter image description here


A PSTricks solution only for fun purposes.

\documentclass[pstricks,12pt]{standalone}
\usepackage{pst-eucl}
\begin{document}
\pspicture(-1,-1)(8,5)
    \psframe[fillstyle=vlines,hatchsep=1pt,linestyle=none](0,-.5)(7,0)
    \pstTriangle[PointName=none,PointSymbol=none](0,0){A}(7,0){B}(0,4){C}
    \pstMarkAngle{C}{B}{A}{$\theta$}
    \pcline(C)(B)\naput[npos=-.05,labelsep=-\pslinewidth,nrot=:U]{\psframe(1,.5)\psframe(8,0)(9,.5)\pcline{->}(8.25,.75)(8.75,.75)\naput[labelsep=12pt]{\rput{*0}{$\vec{v}$}}}
    \pcline[offset=10pt]{|*-|*}(A)(C)\naput{$h$}
\endpspicture
\end{document}

enter image description here

Tags:

Tikz Pgf