Seite 1 von 1

Fläche unter (angeschnittener) Sinus-Fkt. einfärben

Verfasst: Di 6. Feb 2018, 15:03
von lenherrg
Liebe Experten,

der Plot zeigt eine Phasenabschnitssteurung, z.B. in einem Dimmer.

Gerne möchte ich die Fläche unterhalb der Funktion (bei der zweiten Halbwelle oberhalb) bis zur x-Achse einfärben.

Ich habe verschiedenes probiert, bin aber leider gescheitert.
Ich wäre froh um Hilfe. Danke im voraus!!
% Das ist mein LaTeX-Dokument.
\documentclass[12pt,a4paper]{article}
\usepackage[left=2cm,right=2cm,top=2cm,bottom=2cm]{geometry}
\usepackage{tikz} 		% Kopf- und Fusszeile, Grid (auch Farbe und Grafik)


\begin{document}
Phasenabschnittsteuerung\\
\begin{center}
\begin{tikzpicture}[
x=0.3cm, y=1cm,  scale=1.0, 
font=\footnotesize,
>=latex   %Voreinstellung für Pfeilspitzen
]

% Gitternetzlinien
%\draw[xstep=1.2cm, ystep=0.8cm, line width=0.1mm, color=lightgray] (0,-2.25) grid (42.25,2.25);

% x-Achse
\draw[->] (-0,0) -- (35,0) node[below] {$t$}; 
%Zahlen auf x-Achse
\foreach \x in {10,20,...,30}
\draw[shift={(\x,0)},color=black] (0pt,2pt) -- (0pt,-2pt) node[below] {};

% y-Achse 
\draw[->] (0,-2.5) -- (0,2.5) node[left] {$U$};

\draw[thick,color=gray, line width = 0.5pt, dotted] plot[samples=500, domain=0:3.18*pi] 
(\x,{2*sin((0.1*pi)*\x r)});
\draw[thick,color=gray, line width = 0.5pt, dotted] plot[samples=500, domain=3.18*pi:6.37*pi] 
(\x,{2*sin((0.1*pi)*\x r)});
\draw[thick,color=gray, line width = 0.5pt, dotted] plot[samples=500, domain=6.37*pi:9.55*pi] 
(\x,{2*sin((0.1*pi)*\x r)});
\draw[thick,color=gray, line width = 0.5pt, dotted] plot[samples=500, domain=9.55*pi:10.5*pi] 
(\x,{2*sin((0.1*pi)*\x r)});
\node[] at (25, -1.75) {\footnotesize \textcolor{black}{50\,\% Helligkeit}};
\draw[line width = 1pt, blue] (10,0) -- (5,0); 
\draw[line width = 1pt, blue] (5,0) -- (5,2); 
\draw[thick,color=gray, line width = 1pt, blue] plot[samples=500, domain=0*pi:1.57*pi] 
(\x,{2*sin((0.1*pi)*\x r)});
\draw[line width = 1pt, blue] (20,0) -- (15,0); 
\draw[line width = 1pt, blue] (15,0) -- (15,-2); 
\draw[thick,color=gray, line width = 1pt, blue] plot[samples=500, domain=3.18*pi:4.75*pi] 
(\x,{2*sin((0.1*pi)*\x r)});
\draw[line width = 1pt, blue] (30,0) -- (25,0); 
\draw[line width = 1pt, blue] (25,0) -- (25,2); 
\draw[thick,color=gray, line width = 1pt, blue] plot[samples=500, domain=6.36*pi:7.93*pi] 
(\x,{2*sin((0.1*pi)*\x r)});
\end{tikzpicture}
\end{center}


\end{document}
% Ende des Dokumentes 


Das beigefügte Bild zeigt, wie ich es gerne hätte.[/code]

Vielen herzlichen Dank im voraus!
LenherrG

Verfasst: Di 6. Feb 2018, 15:26
von Bartman
Hast Du auch eine der folgenden Herangehensweisen versucht?

Wie kann ich die Fläche zwischen mehreren Pfaden füllen?

Verfasst: Di 6. Feb 2018, 16:06
von markusv
Wahrscheinlich viel zu umständlich, aber basierend auf dem von Bartman gestellten Link (Wie kann ich die Fläche zwischen mehreren Pfaden füllen?) mein folgendes Minimalbeispiel. Habe die Kurvenverläufe auf je ein Befehl zusammengefasst:
\documentclass[tikz]{standalone}
\usetikzlibrary{backgrounds}
\begin{document}
\begin{tikzpicture}[
x=0.3cm, y=1cm,  scale=1.0, 
font=\footnotesize,
>=latex   %Voreinstellung für Pfeilspitzen
]
\def\kurve{plot[samples=100, domain=0*pi:1.57*pi] (\x,{2*sin((0.1*pi)*\x r)}) -- (5,0) -- (10,0) -- plot[samples=100, domain=3.18*pi:4.75*pi] (\x,{2*sin((0.1*pi)*\x r)}) -- (15,0) -- (20,0) -- plot[samples=100, domain=6.36*pi:7.93*pi] (\x,{2*sin((0.1*pi)*\x r)}) -- (25,0) -- (30,0)}
\def\hilfs{plot[samples=500, domain=0:10.5*pi] (\x,{2*sin((0.1*pi)*\x r)})}
% x-Achse
\draw[->] (-0,0) -- (35,0) node[below] {$t$}; 
%Zahlen auf x-Achse
\foreach \x in {10,20,30}
\draw[shift={(\x,0)},color=black] (0pt,2pt) -- (0pt,-2pt) node[below] {};
% y-Achse 
\draw[->] (0,-2.5) -- (0,2.5) node[left] {$U$};
\draw[thick,color=gray, line width = 0.5pt, dotted] \hilfs;
\node[] at (25, -1.75) {\footnotesize \textcolor{black}{50\,\% Helligkeit}}; 
\draw[thick,color=gray, line width = 1pt, blue] \kurve;
\begin{scope}[on background layer]
\clip \kurve;
\fill[yellow!50]\hilfs |- cycle;% Füllen der Schnittfläche
\end{scope}
\end{tikzpicture}
\end{document}

Verfasst: Di 6. Feb 2018, 16:18
von Bartman
Der Befehl \sin ist schon belegt. Wenn ich \def durch \newcommand austausche, bekomme ich eine Fehlermeldung.
\documentclass[tikz]{standalone}
\usetikzlibrary{backgrounds}
\begin{document}
\begin{tikzpicture}[
	x=0.3cm, y=1cm,  scale=1.0, 
	font=\footnotesize,
	>=latex   %Voreinstellung für Pfeilspitzen
]
\def\kurve{plot[samples=100, domain=0*pi:1.57*pi] (\x,{2*sin((0.1*pi)*\x r)}) -- (5,0) -- (10,0) -- plot[samples=100, domain=3.18*pi:4.75*pi] (\x,{2*sin((0.1*pi)*\x r)}) -- (15,0) -- (20,0) -- plot[samples=100, domain=6.36*pi:7.93*pi] (\x,{2*sin((0.1*pi)*\x r)}) -- (25,0) -- (30,0)}
\def\sinus{plot[samples=500, domain=0:10.5*pi] (\x,{2*sin((0.1*pi)*\x r)})}
% x-Achse
\draw[->] (-0,0) -- (35,0) node[below] {$t$}; 
%Zahlen auf x-Achse
\foreach \x in {10,20,30}
\draw[shift={(\x,0)},color=black] (0pt,2pt) -- (0pt,-2pt) node[below] {};
% y-Achse 
\draw[->] (0,-2.5) -- (0,2.5) node[left] {$U$};
\draw[thick,color=red, line width = 0.5pt, dotted] \sinus;
\node at (25, -1.75) {50\,\% Helligkeit};% <- geändert 
\draw[thick,color=gray, line width = 1pt, blue] \kurve;
\begin{scope}[on background layer]
\clip \kurve;
\fill[yellow!50]\sinus |- cycle;% Füllen der Schnittfläche
\end{scope}
\end{tikzpicture}
\end{document}

Verfasst: Di 6. Feb 2018, 16:21
von markusv
Bartman hat geschrieben:Der Befehl \sin ist schon belegt. Wenn ich \def durch \newcommand austausche, bekomme ich eine Fehlermeldung.
Selbstverständlich :oops: Habe es geändert. Der Tag ist schon lang. :roll:

LenherrG

Verfasst: Di 6. Feb 2018, 16:51
von lenherrg
Hallo liebe Experten,

vielen herzlichen Dank... Da habe ich wiedermal was WICHTIGES lernen können. Einfach toll, wie schnell jeweils eine Lösung daherrauscht.

Gruss LenherrG