1

I need to draw something in TikZ, but I am still inexperienced. Can someone help and draw this in TikZ? Thank you very much.

enter image description here

3
  • If you really want to use 3D coordinates, you should look at tikz-3dplot. While there are built-in matrix and grid facilities in tikz, you might just draw 10 lines or 16 rectangles. Mar 2 at 14:29
  • Welcome to TeX.SX! On this site, a question should typically revolve around an abstract issue (e.g. "How do I get a double horizontal line in a table?") rather than a concrete application (e.g. "How do I make this table?"). Questions that look like "Please do this complicated thing for me" tend to get closed because they are either "off topic", "too broad", or "unclear". Please try to make your question clear and simple by giving a minimal working example (MWE): you'll stand a greater chance of getting help.
    – Rmano
    Mar 2 at 15:26
  • ...or you can start here: tex.stackexchange.com/questions/552213/…
    – Rmano
    Mar 2 at 15:28
4

the requested diagram

\documentclass{standalone}
\usepackage{tikz}
\begin{document}
    \begin{tikzpicture}
        \tikzset{sphere/.style={
            draw,
            thick,
            #1!75!black,
            ball color=#1,
            circle,
        }}
        \tikzset{arrow/.style={
            very thick,
            ->,
            >=latex
        }}
        \draw[fill=red, draw=none] (2, 1) rectangle (3, 2);
        \draw[fill=red, draw=none] (1, 2) rectangle (2, 3);
        \draw[thick] (0, 0) grid (4, 4);
        \node[sphere=blue, minimum size=0.5cm] (projection) at (1.5, 2.5) {};
        \node[sphere=blue, minimum size=1cm] (ball) at (0.8, 5) {};
        \draw[arrow, blue] (ball.south) -- (projection.north west) node[pos=0.15, right, color=black] {\footnotesize Projection};
        \node at (1.15, 2.15) {\scriptsize\(p_j\)};
        \node[below left] at (ball.south west) {\(n_j\)};
        
        \begin{scope}[xshift=6cm]
            \draw[fill=red, draw=none] (2, 1) rectangle (3, 2);
            \draw[fill=red, draw=none] (1, 2) rectangle (2, 3);
            \draw[thick] (0, 0) grid (4, 4);
            \node[sphere=blue, minimum size=0.5cm] (projection) at (1.5, 2.5) {};
            \node[sphere=blue, minimum size=1cm] (ball) at (0.8, 5) {};
            \draw[arrow, blue] (ball.south) -- (projection.north west) node[pos=0.15, right, color=black] {\footnotesize Projection};
            \node at (1.15, 2.15) {\scriptsize\(p_j\)};
            \node[below left] at (ball.south west) {\(n_j\)};
            \node[sphere=green, minimum size=0.5cm] (projection2) at (2.5, 1.5) {};
            \node[sphere=green, minimum size=1cm] (ball2) at (3.2, 5) {};
            \node at (2.825, 1.15) {\scriptsize\(p_{j'}\)};
            \node[below left] at (ball2.south west) {\(n_j\)};
            \draw[arrow, green] (ball2.south) -- (projection2.north);
            \draw[arrow] (projection2.north west) -- (projection.south east);
        \end{scope}
    \end{tikzpicture}
\end{document}

The key commands used here are

\draw (a, b) grid (c, d);

draws a grid from (a, b) to (c, d).

\fill[<colour>] (a, b) rectangle (c, d);

draws a rectangle with diagonally opposite corners (a, b) and (c, d) rectangle has no boundary and is filled with the colour <colour>.

\node[circle, ball color=<colour>, minimum size=xcm] at (a, b) {};

draws a circle of colour <colour> and diameter x measured in centimeters at (a, b).

I also made use of nodes and coordinates, in particular if you do

\node (name) at (a, b) {};
\draw (name.south) -- (c, d);

then this places a node at (a, b) and calls the node name. The second command then draws a straight line from the bottom of node (.south other compass directions work similarly) to the point (c, d).

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.