TikZ-StructuralAnalysis
TikZ-StructuralAnalysis copied to clipboard
Add option to draw any curve between two points as lineload
Hello,
I am a student assistant for a structural mechanics course and prepare presentations, as well as assignments with this amazing package. I our course however, we use more intricate lineloads than just linear ones. It would be nice to have a curved option (like bezier curves, I think tikzpgf supplies that) that allows to shape them.
E.g.: It would be a lineload type where I would give the control point of the curve.
Sadly I do not know TeX well enough to modify the .sty file myself.
How much effort would it be to add that? I can try to pr a solution, but that may not be up to standards.
Chenjox
After some experimenting with the tikz plot
command, I have created something that might work for the most things
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
\coordinate (c3) at (0.0,0.0);
\draw[very thin,gray] (-6.0,-6.0) grid (6.0,6.0);
\draw[thick, black] (-6.0,0.0) -- (6.0,0.0);
\draw[thick, black] (0.0,-6.0) -- (0.0,6.0);
% Now to draw the function betwenn to points that are 6 units apart.
\begin{scope}[rotate around={45:(c3)},shift={(-1.0,-1.0)}]
\path (0.0,0.0) coordinate (tempS) +(6.0,0.0) coordinate (tempE);
\draw[thick] (tempS) -- plot[domain=0:6] (\x,{2*\x/6*\x/6-1}) -- (tempE) -- cycle;
\draw[clip] (tempS) -- plot[domain=0:6] (\x,{2*\x/6*\x/6-1}) -- (tempE) -- cycle;
\foreach \p in {0.0,0.1,0.2,...,0.9,1.0}{
\path (0.0,0.0) -- plot[domain=0:6*\p] (\x,{2*\x/6*\x/6-1}) coordinate (t1);
\path (tempS) -- (tempE) coordinate[pos=\p] (t2);
\draw[thick,-latex] (t1) -- (t2);
};
\end{scope}
\end{tikzpicture}
\end{document}
Currently I create a path from (a)
to (b)
, whose ends are saved in the coordinates (tempS)
and (tempE)
I then plot a function, with a specific domain (which cooincides with the ends of the line ab
) - afterwards I plot the same path again, but only to clip it (meaning only everything inside the umscibed region gets drawn).
Afterwards I draw the arrows of the lineload, by ending the domain at the specified point and drawing an arrow to the baseline.
The current problem is, that I need to somehow include the function in a macro (because the function itself contains a macro this might not work) and need to somehow calculate the distance between the points (I think calc
can do that, I haven't found the specific part yet.)
If this Idea is good enough, I will make a PR for the package
Upon further examination and helpful insight from https://tex.stackexchange.com/questions/492035/plot-along-path-in-tikz I came up with the following
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{stanli}
\tikzset{plot along line/.style args={from #1 to #2}{insert
path={
let \p1=($#2-#1$),\n1={veclen(\x1,\y1)/1cm},\n2={atan2(\y1,\x1)}
in [shift={#1},rotate=\n2,domain=0:\n1]
}}}
\tikzset{plot along line until/.style args={from #1 to #2 until #3}{insert
path={
let \p1=($#2-#1$),\n1={veclen(\x1,\y1)/1cm},\n2={atan2(\y1,\x1)}
in [shift={#1},rotate=\n2,domain=0:\n1*#3]
}}}
% von, zu, plot
\newcommand{\lineloadex}[3]{
\coordinate (VarA) at ($ (#1)!0.2cm!90:(#2) $);
\coordinate (VarB) at ($ (#2)!0.2cm!-90:(#1) $);
\begin{scope}
\draw[thick,line join=bevel] {[plot along line=from (VarA) to (VarB)](VarA) -- plot (#3)} -- (VarB) -- cycle;
\draw[clip] {[plot along line=from (VarA) to (VarB)](VarA) -- plot (#3)} -- (VarB) -- cycle;
\foreach \u in {0.0,0.1,0.2,...,1.0}{
\path {[plot along line until=from (VarA) to (VarB) until \u ] (VarA) -- plot (#3) coordinate (t1)} ;
\path (VarA) -- (VarB) coordinate[pos=\u] (t2);
\draw[thick,-latex] (t1) -- (t2);
};
\end{scope}
}
\begin{document}
\begin{tikzpicture}
\point{p1}{0.0}{0.0}
\point{p2}{3.0}{2.0}
\beam{1}{p1}{p2}
\support{1}{p1}
\support{1}{p2}
\hinge{1}{p1}
\hinge{1}{p2}
\lineloadex{p1}{p2}{\x,{-1/3*\x*(\x-3.606)}}
\end{tikzpicture}
\end{document}
This results in
Which I think is good enough.