How to draw a cross section of an engine in TikZ - latex

I would like to convert the following picture, which is a cross section of an engine, into a TikZ code:
How to start with this picture?
How to draw the walls and pipes in an easy way?
How to draw the oil (the hatched area)?

How to draw the oil (the hatched area)?
One way may be to use pattern=north east lines from patterns library described at page 730 of the PGF Manual:
\documentclass[tikz,border=5mm]{standalone}
\usetikzlibrary{patterns}
\begin{document}
\begin{tikzpicture}
\fill [pattern=north east lines] (0,6) -- (0,0) -- (10,0) -- (10,6);
\draw (0,10) -- (0,0) -- (10,0) -- (10,10);
\end{tikzpicture}
\end{document}

Related

How to make a graphic where one image points to two other images with arrows in latex?

I want to create a graphic like the one in the attached image in latex, where each box represents an image (a graphic I want to insert). I also want to be able to write a word over the arrows that point from one image to another.
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
\begin{figure}[htb]
\centering
\begin{tikzpicture}[>=latex,node distance=2em]
\node(a){\includegraphics[width=4cm]{example-image-a}};
\node[right=of a](b){\includegraphics[width=4cm]{example-image-b}};
\draw[->] (a) -- (b);
\end{tikzpicture}
\caption{Two graphics.}
\end{figure}
\begin{figure}[htb]
\centering
\begin{tikzpicture}[>=latex,node distance=2em]
\node(a){\includegraphics[width=3cm]{example-image-a}};
\matrix[right=of a,row sep=2em] {
\node(b){\includegraphics[width=3cm]{example-image-b}};\\
\node(c){\includegraphics[width=3cm]{example-image-duck}};\\
};
\draw[->] (a) -- (b);
\draw[->] (a) -- (c);
\end{tikzpicture}
\caption{Three graphics.}
\end{figure}
\end{document}
visit: https://tex.stackexchange.com/questions/527216/diagrams-arrows

Generating random points then connecting points less than certain distance away

I currently have the code below which produces the later output. I would like to generate the 10 points randomly as I already am. But instead of having blue dashed lines connecting to the the location (0,0), I want them to connect to the other dots if the distance is less than 4cm away.
I attempted things such as storing the data into arrays but updating and accessing the values was not working. I attempted nested for loops but handling the seed became difficult. What is a good way to do this?
\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw[step=0.5cm,color=gray] (-2.5,-2.5) grid (2.5,2.5);
\pgfmathsetseed{2}
\foreach \x in {1,...,10}
{
\pgfmathrandominteger{\a}{-240}{240}
\pgfmathrandominteger{\b}{-240}{240}
\fill [color=red,anchor=center](\a*0.01,\b*0.01) circle (0.1);
% CHANGE HERE
\draw [color=blue,densely dotted] (\a*0.01,\b*0.01) -- (0.0,0.0);
};
\end{tikzpicture}
\end{document}
I seemed to have figured out a solution (not ideal but works for this case).
The key was to use the \pgfmathparse for performing the if statement to get a 0 or 1 to use in \ifnum.
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{math}
\begin{document}
\begin{tikzpicture}
\draw[step=0.5cm,color=gray] (-2.5,-2.5) grid (2.5,2.5);
\pgfmathsetseed{2}
\foreach \x in {1,...,10}
{
\pgfmathrandominteger{\a}{-240}{240}
\pgfmathrandominteger{\b}{-240}{240}
\fill [color=red,anchor=center](\a*0.01,\b*0.01) circle (0.1);
\pgfmathsetseed{2}
\foreach \y in {0,...,\x}
{
\pgfmathrandominteger{\c}{-240}{240}
\pgfmathrandominteger{\d}{-240}{240}
\tikzmath{\i=(\a*0.01-\c*0.01)^2;}
\tikzmath{\j=(\b*0.01-\d*0.01)^2;}
\tikzmath{\k=\i+\j;}
\pgfmathparse{\k < 4.0 ? 1 : 0}
\ifnum\pgfmathresult=1
\draw [color=blue,densely dotted] (\a*0.01,\b*0.01) -- (\c*0.01,\d*0.01);
\fi
};
};
\end{tikzpicture}
\end{document}

Aiming an arrow at a target

I am writing a carom billard instruction manual in Latex. Illustrations are made with tikz. I need an arrow that always points from the cue ball in the direction to the object ball and is always the same lenght and at the same distance from the cue ball.
I have a solution drawing an arrow from cueball to object ball and shortening the line. This shortening however has to be done manually every time the distance between the balls changes, by trial and error.
Is there a way to automate this so I don't have to change the lenght by hand?
\documentclass[a4paper, 11pt]{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\usetikzlibrary{arrows,arrows.meta}
\begin{document}
\begin{tikzpicture}[x=1mm, y=1mm]
% Units definitions
\def \tb {142} % width of table
\def \tl {2*\tb} % lenght of table
\def \d {\tb/4}; % diamonds
\def \c {\tb/3}; % Cadre
\def \bb {6.15}; % diameter of balls
% Cueball coordinate
\path (\c,\c) coordinate (B1);
% Objectball coordinate
\path (1.5*\bb,\c-\bb) coordinate (B2);
% Arrow
\draw [-Stealth, thick, shorten >=125, shorten <=30]
(B1) --
(B2);
% Cueball
\draw [fill=white] (B1)
node[above left = 5]{\small Cueball} % Beschriftung
circle (\bb/2);
% Objectball
\draw [fill=white] (B2)
node[above left = 5]{\small Objectball} % Beschriftung
circle (\bb/2);
\end{tikzpicture}
\end{document}
Here is how you could draw the cue stick (you can add draw,red to the fake line and circles to see how this is constructed):
\def \distancetoball {6mm};
\def \sticklength {20mm};
% Define fake line that goes through the object ball and the cue ball
\path [name path=direction] ($(B1)!-\distancetoball-\sticklength!(B2)$) -- (B2);
% Define two fake circles around the cueball to place the cue stick
\path [name path=circle1] (B1) circle(\distancetoball);
\path [name path=circle2] (B1) circle(\distancetoball+\sticklength);
% Pick the intersection of the line with the two circles to be the two extremities of the cue stick
\path [name intersections={of=direction and circle1}];
\coordinate (tip) at (intersection-1);
\path [name intersections={of=direction and circle2}];
\coordinate (source) at (intersection-1);
% Draw the cue stick
\draw [-Stealth, thick] (source) -- (tip);

How to draw nodes with "stubs" in Latex?

I'm trying to draw this in latex.
Anyone know how?
Use the calc-library and do the following:
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
\node[draw=black, circle, fill=green] (A) at (0,0) {A};
\draw let \p1=(A) in (A) -- (\x1+40,\y1+10);
\end{tikzpicture}
\end{document}
Using the let-statement it allows you to specify a reference point (or even more) to use it's coordinates for further calculation.

How to change arrow tip in tikz

Is there a simple way to increase the size of an arrow tip using something like:
\tikzset{myptr/.style=->, ????}
without designing a new arrow style from scratch?
One solution, very quick, to just scale the arrow head is number %2 in the following:
\documentclass[multi=false,tikz,border=2mm]{standalone}
\usetikzlibrary{arrows,decorations.markings}
\begin{document}
\begin{tikzpicture}
%1
\draw [->,>=stealth] (0,.5) -- (2,.5);
%2
\draw [decoration={markings,mark=at position 1 with
{\arrow[scale=3,>=stealth]{>}}},postaction={decorate}] (0,0) -- (2,0);
\end{tikzpicture}
\end{document}
This produces:
(sorry for excessive zoom).
Much more in the answers to this question and in this answer, that I used as a source.
Addendum
\tikzset approach. This code:
\documentclass[multi=false,tikz,border=2mm]{standalone}
\usetikzlibrary{arrows,decorations.markings}
\begin{document}
\begin{tikzpicture}
\tikzset{myptr/.style={decoration={markings,mark=at position 1 with %
{\arrow[scale=3,>=stealth]{>}}},postaction={decorate}}}
%1
\draw [->,>=stealth] (0,.5) -- (2,.5);
%2
\draw [myptr] (0,0) -- (2,0);
\end{tikzpicture}
\end{document}
produces the same output as the above one (source: PGF Manual, section 2.8).
Obviously you can use -Latex instead of stealth.
There is a new solution, see https://latexdraw.com/exploring-tikz-arrows/#t-1610685307397. It allows changing both the length and width of arrows:
\documentclass[border=1mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,arrows}
\begin{document}
\begin{tikzpicture}
\draw [-{Stealth[length=3mm, width=2mm]}] (0,0.5) -- (1,0.5);
\draw [-stealth] (0,0) -- (1,0);
\end{tikzpicture}
\end{document}

Resources