# How to draw two triangles on a non-horizontal line?

I'm a beginner on TikZ package and trying to draw two triangles on a non-horizontal line, as shown below.

Is there any way to draw the triangles first on a straight line and then rotate them?

• Welcome to TexSE. The simple answer is "yes, as explained in the manual". A quick search of the manual with the string "rotate" would show you that \draw[rotate=30]... might give you a starting point. In general you will get more help here (a) if you ask a specific question about how to do something and (b) you show us what you have already tried in the form of a working example we can compile. – Thruston Oct 1 '16 at 13:53

A starting point. The code duplication for the two triangles is avoided by a \foreach loop.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows.meta}
\usepackage{xcolor}
\begin{document}
\begin{tikzpicture}
\def\AngleS{20}
\def\AngleTheta{45}
\def\ArrowLen{2cm}
\definecolor{rosa}{HTML}{F79796}
\definecolor{myred}{HTML}{EE1450}
\definecolor{myblue}{HTML}{0083CA}
\tikzset{
myarrowtip/.tip={Triangle[length=12pt, width=8pt]},
myarrow/.style={draw={#1},line width=2.5pt, -{myarrowtip}},
}
\draw
(\AngleS:9cm) node (s) {$s$}
(0, 0) --
coordinate[pos=.22] (si)
coordinate[pos=.66] (sf)
(s)
;
\foreach \start/\ssub in {si/i, sf/f} {
\draw
(\start) ++(\AngleS + \AngleTheta/2:\RadiusTheta + 1.5ex)
node {$\theta$}
;
\draw[myarrow=rosa]
(\start) -- ++(\AngleS:\ArrowLen)
coordinate (tmpA)
node[below] {$\vec F_s$}
;
\draw[myarrow=red]
(\start) -- ++(\AngleS + \AngleTheta:{\ArrowLen/cos(\AngleTheta)})
coordinate (tmpB)
node[left] {$\vec F$}
;
\draw[dashed] (tmpA) -- (tmpB);
(\start) circle[]
++(\AngleS - 90:1em) node {$s_{\ssub}$}
;
}
\draw[myarrow=myblue]
(si) ++(\AngleS - 90:2em)
-- node[below] {$\Delta \vec r$}
++(\AngleS:{(.66 - .22) * 9cm})
;
\end{tikzpicture}
\end{document}


• Regarding the original question, whether it is possible to draw everything horizontally and then rotate it: Just replace all occurrences of \AngleS in the \draw commands by zero, and put the commands into a scope environment starting with \begin{scope}[rotate=\AngleS] and terminating with \end{scope}. This makes the code even a bit simpler (though it is already quite compact). – gernot Oct 1 '16 at 16:23
• I suppose it also rotates the labels? – Bernard Oct 1 '16 at 17:15
• @Bernard No. It just rotates the coordinates. If you want to rotate anything, then the rotation needs to be applied to the canvas: transform canvas={rotate=\AngleS}. – Heiko Oberdiek Oct 1 '16 at 17:29