Re: Le mie (dis)avventure con TikZ

#96835
Up
0
Down
::

lorenzo.pantieri” post=107370Ecco altre due immagini che ho realizzato alla buona. Se avete suggerimenti su come migliorarne il (pessimo) codice, sono qui. Ah, per tutta una serie di ragioni (molte delle quali certamente infondate) sono fermo alla MacTeX 2013, quindi vi chiedo di evitare librerie troppo moderne.

`\documentclass{article}
\usepackage[dvipsnames]{xcolor}
\usepackage{tikz,pgfplots,amsmath}

\begin{document}

\begin{tikzpicture}[font=\small]
\begin{axis} [width=0.4\textwidth,
axis lines=middle,
xmin=0,xmax=4,ymin=0,ymax=20,
enlargelimits,
grid,
xtick={1,2,3,4,5,6},
ytick={5,10,15,20},
xlabel=$x$,
ylabel=$y$]

\addplot [domain=0:10, samples=100,smooth,blue,very thick] {5/x};

\end{axis}
\end{tikzpicture}

\begin{tikzpicture} [decoration={coil,aspect=0.3,segment length=1mm,amplitude=1mm},font=\small,scale=1.15]

\draw [thick] (0,0) — (4.5,0) — (0,2.59808) — cycle;

\draw [thick,fill=BrickRed!50!white,rounded corners,shift={(2.10192,1.84641)},rotate =-30] (-0.9,-0.4) rectangle (0.9,0.4);

% asse x
\draw [->,shift={(2.10192,1.84641)},rotate =-30] (0,0) — (1.5,0);
\node [shift={(2.10192,1.84641)},rotate =-30,below=5pt] at (1.75,0) {$x$};

% asse y
\draw [->,shift={(2.10192,1.84641)},rotate =-30] (0,0) — (0,1.75);
\node [shift={(2.10192,1.84641)},rotate =-30,right=20pt] at (0,2) {$y$};

\draw [->,shift={(2.10192,1.84641)},rotate =-30] (0,0) — (1.5,0);

% P
\draw [blue,very thick,->] (2.10192,1.84641) — (2.10192,0.34641);
\node

at (2.10192,0.34641) {$\vec{P}$};

% P perpendicolare
\draw [blue,very thick,->,shift={(2.10192,1.84641)},rotate =-30] (0,0) — (0,-1.29904);
\node [below] at (1.3,0.9) {$\vec{P}_{\bot}$};

% P parallelo
\draw [blue,very thick,->,shift={(2.10192,1.84641)},rotate =-30] (0,0) — (0.75,0);
\node [below] at (2.7,2.1) {$\vec{P}_{\parallel}$};

% reazione vincolare
\draw [blue,very thick,red,->,shift={(2.10192,1.84641)},rotate =-30] (0,0) — (0,1.29904);
\node

at (2.7,2.6) {$\vec{F}_{\text{v}}$};

% forza elastica
\draw [blue,very thick,green,->,shift={(2.10192,1.84641)},rotate =-30] (0,0) — (-0.75,0);
\node [below] at (1.7,2.7) {$\vec{F}_\text{e}$};

\draw [<->,dashed] (-0.25,-0) — (-0.25,2.59808);
\node

at (-0.25,1.29904) {$h$};

\draw [<->,dashed] (0,-0.25) — (4.5,-0.25);
\node [below] at (2.25,-0.25) {$d$};

\draw

(-2.75,-0.1) rectangle (-2,0.1);

\draw [dashed,shift={(2.10192,1.84641)},rotate =-30] (0,-1.3) — (0.75,-1.3);

\draw [dashed,shift={(2.10192,1.84641)},rotate =-30] (0.75,-1.25) — (0.75,0);

\draw [decorate,shift={(2.10192,1.84641)},rotate =-30] (-2.0,0.0) — (-0.9,0.0);

\end{tikzpicture}

\end{document}`

Prova così: `\documentclass{article}
\usepackage[dvipsnames]{xcolor}
\usepackage{tikz,pgfplots,amsmath}

\pgfplotsset{compat=1.3} % versione super vecchia di pgfplots 😉

\begin{document}

\begin{tikzpicture}[font=\small]
\begin{axis} [width=0.4\textwidth,
axis lines=middle,
xmin=0,xmax=4,ymin=0,ymax=20,
enlargelimits,
grid,
xtick={1,2,3,4,5,6},
ytick={5,10,15,20},
xlabel=$x$,
ylabel=$y$,
% vedi: http://tex.stackexchange.com/q/122747/13304
every axis x label/.style={
at={(ticklabel* cs:1.05)},
anchor=west,
},
every axis y label/.style={
at={(ticklabel* cs:1.05)},
anchor=south,
},
]

\addplot [domain=0:10, samples=100,smooth,blue,very thick] {5/x};

\end{axis}
\end{tikzpicture}

\vspace*{1cm}

\begin{tikzpicture} [decoration={coil,aspect=0.3,segment length=1mm,amplitude=1mm},font=\small,scale=1.15]

\draw [thick] (0,0) — (4.5,0) — (0,2.59808) — cycle;

\draw [thick,fill=BrickRed!20,rounded corners,shift={(2.10192,1.84641)},rotate =-30] (-0.9,-0.4) rectangle (0.9,0.6);% <= ho alzato il vertice alto a destra e sfumato leggermente di più il riempimento % asse x \draw [->,shift={(2.10192,1.84641)},rotate =-30] (0,0) — (1.5,0);
\node [shift={(2.10192,1.84641)},rotate =-30,below=5pt] at (1.75,0) {$x$};

% asse y
\draw [->,shift={(2.10192,1.84641)},rotate =-30] (0,0) — (0,1.75);
\node [shift={(2.10192,1.84641)},rotate =-30,right=20pt] at (0,2) {$y$};

\draw [->,shift={(2.10192,1.84641)},rotate =-30] (0,0) — (1.5,0);

% P
\draw [blue,very thick,->] (2.10192,1.84641) — (2.10192,0.34641);
\node

at (2.10192,0.34641) {$\vec{P}$};

% P perpendicolare
\draw [blue,very thick,->,shift={(2.10192,1.84641)},rotate =-30] (0,0) — (0,-1.29904);
\node [below] at (1.3,0.9) {$\vec{P}_{\bot}$};

% P parallelo
\draw [blue,very thick,->,shift={(2.10192,1.84641)},rotate =-30] (0,0) — (0.75,0);
\node [below] at (2.7,2.1) {$\vec{P}_{\parallel}$};

% reazione vincolare
\draw [blue,very thick,red,->,shift={(2.10192,1.84641)},rotate =-30] (0,0) — (0,1.29904);
\node

at (2.7,2.6) {$\vec{F}_{\text{v}}$};

% forza elastica
\draw [blue,very thick,green,->,shift={(2.10192,1.84641)},rotate =-30] (0,0) — (-0.75,0);
\node [below] at (1.7,2.7) {$\vec{F}_\text{e}$};

\draw [<->,dashed] (-0.25,-0) — (-0.25,2.59808);
\node

at (-0.25,1.29904) {$h$};

\draw [<->,dashed] (0,-0.25) — (4.5,-0.25);
\node [below] at (2.25,-0.25) {$d$};

\draw

(-2.75,-0.1) rectangle (-2,0.1);

\draw [dashed,shift={(2.10192,1.84641)},rotate =-30] (0,-1.3) — (0.75,-1.3);

\draw [dashed,shift={(2.10192,1.84641)},rotate =-30] (0.75,-1.25) — (0.75,0);

\draw [decorate,shift={(2.10192,1.84641)},rotate =-30] (-2.0,0.0) — (-0.9,0.0);

\end{tikzpicture}

\end{document}` Il codice è commentato e le modifiche sono veramente minime 😉

Ciao
Claudio

Go to top