TeX - LaTeX Asked by Nikola Zubic on April 1, 2021
I need to draw something in TikZ, but I am still inexperienced. Can someone help and draw this in TikZ? Thank you very much.
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)
.
Correct answer by Willoughby on April 1, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP