%%
%%  Mathe Makros (auch außerhalb der BMS)
%%  2025_05_30
%%  Autor: philipp.freimann@bms-w.c0
%%
%% Graphiken mit tikz und BMS-W Mathe-Makros
%%
\tikzset{bbwgrid/.style={help lines,color=bbwMMFarbe!25,thick,step=0.5cm}}

%% einfach die folgende Zeile neu definieren bei kleineren Graphen und
%% scale auf z. B. 0.5 setzen
\tikzset{graphSkalierung/.style={xscale=1,yscale=1}}

%% Koordinatensystem ohne Zahlen
\newcommand{\bbwGridPartLeer}[4]{
 % grid:
 \draw[bbwgrid,graphSkalierung] (#1,#3) grid (#2,#4);

 % axes
 \draw[thick,graphSkalierung] (#1,0) -- (#2,0);
 \draw[thick,graphSkalierung] (0,#3) -- (0,#4);
 \foreach \x in {#1, ..., -1}  \draw[graphSkalierung] (\x cm, 3pt) -- (\x cm, -3pt);%%  node[anchor=north]{$\x$};
 \foreach \x in {1, ..., #2}   \draw[graphSkalierung] (\x cm, 3pt) -- (\x cm, -3pt);%%  node[anchor=north]{$\x$};
 \foreach \y in {#3, ..., -1}  \draw[graphSkalierung] (-3pt, \y cm) -- (3pt, \y cm);%%  node[anchor=east]{$\y\,\,$};
 \foreach \y in {1, ..., #4}   \draw[graphSkalierung] (-3pt, \y cm) -- (3pt, \y cm);%%  node[anchor=east]{$\y\,\,$};
 \draw[->,thick,graphSkalierung] (#2,0) -- ({#2+0.5},0) node[anchor=west]{$x$};
 \draw[->,thick,graphSkalierung] (0,#4) -- (0,{#4+0.5}) node[anchor=south]{$y$};
}

\newcommand{\bbwGridPart}[4]{
 % grid:
 \draw[bbwgrid,graphSkalierung] (#1,#3) grid (#2,#4);

 % axes
 \draw[thick,graphSkalierung] (#1,0) -- (#2,0);
 \draw[thick,graphSkalierung] (0,#3) -- (0,#4);
 \foreach \x in {#1, ..., -1}  \draw[graphSkalierung] (\x cm, 3pt) -- (\x cm, -3pt)  node[anchor=north,graphSkalierung]{\small $\x\,\,\,$};
 \foreach \x in {1, ..., #2}   \draw[graphSkalierung] (\x cm, 3pt) -- (\x cm, -3pt)  node[anchor=north,graphSkalierung]{$\x$};
 \foreach \y in {#3, ..., -1}  \draw[graphSkalierung] (-3pt, \y cm) -- (3pt, \y cm)  node[anchor=east,graphSkalierung]{\small $\y\,\,$};
 \foreach \y in {1, ..., #4}   \draw[graphSkalierung] (-3pt, \y cm) -- (3pt, \y cm)  node[anchor=east,graphSkalierung]{$\y\,\,$};
 \draw[->,thick,graphSkalierung] (#2,0) -- ({#2+0.5},0) node[anchor=west]{$x$};
 \draw[->,thick,graphSkalierung] (0,#4) -- (0,{#4+0.5}) node[anchor=south]{$y$};
 }

%% A function within a Grid (without painting the grid)
%% #1: funciton eg 2*\x  (x has to be backquoted)
%% #2: Domain eg. -1:2.5
%% #3: colour eg red
\newcommand{\bbwFuncC}[3]{\draw[domain=#2,smooth,samples=200,variable=\x,#3] plot ({\x},{#1});
}
%% A function within a Grid (without painting the grid)
\newcommand{\bbwFunc}[2]{\bbwFuncC{#1}{#2}{blue}}

%% Declare a function-plot
%% xmin,xmax,ymin,ymax,fct,domain(x-min, x-max)
%% example: \bbwFunction{-4}{3}{-2}{5}{-\x*\x- \x + 4.5}{-3:2}
\newcommand{\bbwFunction}[6]{\begin{tikzpicture}
\bbwGridPart{#1}{#2}{#3}{#4}
 \bbwFunc{#5}{#6}
%% \draw[domain=#6,smooth,samples=200,variable=\x,blue] plot ({\x},{#5});
\end{tikzpicture}}
%% a whole graph having a coordinate-system #1-#4 and any tizpicture content #5:
\newcommand{\bbwGraph}[5]{\begin{tikzpicture}\bbwGridPart{#1}{#2}{#3}{#4}#5\end{tikzpicture}}
\newcommand{\bbwGraphLeer}[5]{\begin{tikzpicture}\bbwGridPartLeer{#1}{#2}{#3}{#4}#5\end{tikzpicture}}

%% Dots and lines:
%% Dot example: \bbwDot{-1,2}{red}{east}{A}
\newcommand{\bbwDot}[4]{\filldraw[color=#2!60, fill=#2!5, thick](#1) circle(0.05) node[anchor=#3]{$#4$};}

%% Line example: \bbwLine{-1,0}{2,3}{red}
\newcommand{\bbwLine}[3]{\draw[thick,color=#3] (#1)--(#2);}

\newcommand{\bbwArrow}[3]{\draw[thick,color=#3,->] (#1)--(#2);}

%% Strecke mit zwei Endpunkten
%% #1, #2: Koordinaten der Endpunkte
%% #3: Ort der Beschriftung
%% #4: Beschtiftung (z. B. "a)")
%% #5: farbe der Strecke und der Beschriftung
\newcommand{\bbwStrecke}[5]{%%
\bbwLine{#1}{#2}{#5}%
\bbwDot{#1}{#5}{west}{}%
\bbwDot{#2}{#5}{west}{}%
\draw (#3) node{{\color{#5}#4}};
}%%



%% Draw a single letter or small text
% #1: Position eg  4,4
% #2: letter eg f or blah
% #3: colour
\newcommand{\bbwLetter}[3]{\draw[color=#3](#1) node{$#2$};}

%%% ABC-Formel
%% usage \abcd{<a>}{<b>}{<c>}
%% example usage: \abcd{b}{5}{\sqrt{4}}
\newcommand{\abcd}[3]{$\frac{-(#2)\pm\sqrt{(#2)^2 - 4\cdot{}(#1)\cdot{}(#3)}}{2\cdot{}(#1)}$}


%% coordSysBBWFlex
%% Flexibles Koordinatensystem mit Pfeilen und Pfeilbeschriftung, aber
%% noch ohne "ticks".
%% #1   : Rastergröße
%% #2-#5: Größe des Rasters in cm
%% #6   : Beschriftung in x-Richtung (in y-Richtung ist es immer y
%% #7   : Zu zeichnende Funktion
%% #8   : Ticks oder was sonst noch komplexeres in die Grafik muss
\newcommand{\bbwFunctionColour}{blue}
\newcommand{\coordSysBBWFlex}[8]{
\begin{tikzpicture}
\draw[step = #1,  thin, cyan!20] (#2, #4) grid (#3, #5);
\draw[thick, ->] (#2,0) -- (#3,0) node[anchor = west] {$#6$};
\draw[thick, ->] (0,#4) -- (0,#5) node[anchor = south] {$y$};
\draw[domain=#2:#3,smooth,samples=200,variable=\x,\bbwFunctionColour] plot ({\x},{#7});
#8;
\end{tikzpicture}
\renewcommand{\bbwFunctionColour}{blue}
}%% end coordSysBBW

\newcommand{\einheitskreis}{
\definecolor{qqwuqq}{rgb}{0,0.79,0}
\definecolor{qqqqff}{rgb}{0,0,1}
\definecolor{qqzzzz}{rgb}{0,0.6,0.6}
\definecolor{ffwwqq}{rgb}{1,0.4,0}
\definecolor{qqccww}{rgb}{0,0.8,0.4}
\definecolor{uququq}{rgb}{0.25,0.25,0.25}
\definecolor{xdxdff}{rgb}{0.49,0.49,1}
\begin{tikzpicture}[line cap=round,line join=round,>=triangle 45,x=2.5cm,y=2.5cm]
\draw[->,color=black] (-1.5,0) -- (1.5,0);
\foreach \x in {-1.5,-1,-0.5,0.5,1}
\draw[shift={(\x,0)},color=black] (0pt,2pt) -- (0pt,-2pt) node[below] {\footnotesize $\x$};
\draw[->,color=black] (0,-1.5) -- (0,1.5);
\foreach \y in {-1.5,-1,-0.5,0.5,1}
\draw[shift={(0,\y)},color=black] (2pt,0pt) -- (-2pt,0pt) node[left] {\footnotesize $\y$};
\draw[color=black] (0pt,-10pt) node[right] {\footnotesize $0$};
\clip(-1.5,-1.5) rectangle (1.5,1.5);
\draw [shift={(0,0)},color=qqwuqq,fill=qqwuqq,fill opacity=0.1] (0,0) -- (0:0.28) arc (0:46.14:0.28) -- cycle;
\draw(0,0) circle (2.5cm);
\draw [domain=-1.5:1.5] plot(\x,{(-0-0.72*\x)/-0.69});
\draw (0.69,-1.5) -- (0.69,1.5);
\draw (1,-1.5) -- (1,1.5);
\draw (1.12,0.6) node[anchor=north west,color=qqccww] {t};
\draw (0.50,0.42) node[anchor=north west,color=ffwwqq] {s};
\draw (0.30,0.21) node[anchor=north west,color=qqzzzz] {c};
\draw [line width=1.2pt,color=qqccww] (1,1.04)-- (1,0);
\draw [line width=1.2pt,color=ffwwqq] (0.69,0.72)-- (0.69,0);
\draw [line width=1.6pt,color=qqzzzz] (0.69,0)-- (0,0);
\begin{scriptsize}
\fill [color=xdxdff] (0.69,0.72) circle (1.5pt);
\draw[color=xdxdff] (0.49,0.71) node {$P$};
\fill [color=uququq] (0.69,0) circle (1.5pt);
\draw[color=uququq] (0.8,0.12) node {$Xp$};
%%\fill [color=uququq] (1,1.04) circle (1.5pt);
%%\draw[color=uququq] (1.22,0.95) node {$Yp$};
\fill [color=uququq] (0.69,0.72) circle (1.5pt);
\draw[color=uququq] (0.82,0.7) node {$Yp$};
\fill [color=qqqqff] (0,0) circle (1.5pt);
\draw(0.20,0.09) node {$\varphi$};
\end{scriptsize}
\end{tikzpicture}\par
}%% END Command \einheitskreis


\newcommand{\einheitskreisT}{%% Tangens
\definecolor{qqwuqq}{rgb}{0,0.79,0}
\definecolor{qqqqff}{rgb}{0,0,1}
\definecolor{qqzzzz}{rgb}{0,0.6,0.6}
\definecolor{ffwwqq}{rgb}{1,0.4,0}
\definecolor{qqccww}{rgb}{0,0.8,0.4}
\definecolor{uququq}{rgb}{0.25,0.25,0.25}
\definecolor{xdxdff}{rgb}{0.49,0.49,1}
\begin{tikzpicture}[line cap=round,line join=round,>=triangle 45,x=2.5cm,y=2.5cm]
\draw[->,color=black] (-1.5,0) -- (1.5,0);
\foreach \x in {-1.5,-1,-0.5,0.5,1}
\draw[shift={(\x,0)},color=black] (0pt,2pt) -- (0pt,-2pt) node[below] {\footnotesize $\x$};
\draw[->,color=black] (0,-1.5) -- (0,1.5);
\foreach \y in {-1.5,-1,-0.5,0.5,1}
\draw[shift={(0,\y)},color=black] (2pt,0pt) -- (-2pt,0pt) node[left] {\footnotesize $\y$};
\draw[color=black] (0pt,-10pt) node[right] {\footnotesize $0$};
\clip(-1.5,-1.5) rectangle (1.5,1.5);
\draw [shift={(0,0)},color=qqwuqq,fill=qqwuqq,fill opacity=0.1] (0,0) -- (0:0.28) arc (0:46.14:0.28) -- cycle;
\draw(0,0) circle (2.5cm);
\draw [domain=-1.5:1.5] plot(\x,{(-0-0.72*\x)/-0.69});
\draw (0.69,-1.5) -- (0.69,1.5);
\draw (1,-1.5) -- (1,1.5);
\draw (1.12,0.6) node[anchor=north west,color=qqccww] {t};
\draw (0.50,0.42) node[anchor=north west,color=ffwwqq] {s};
\draw (0.30,0.21) node[anchor=north west,color=qqzzzz] {c};
\draw [line width=1.2pt,color=qqccww] (1,1.04)-- (1,0);
\draw [line width=1.2pt,color=ffwwqq] (0.69,0.72)-- (0.69,0);
\draw [line width=1.6pt,color=qqzzzz] (0.69,0)-- (0,0);
\begin{scriptsize}
\fill [color=xdxdff] (0.69,0.72) circle (1.5pt);
\draw[color=xdxdff] (0.49,0.71) node {$P$};
\fill [color=uququq] (0.69,0) circle (1.5pt);
\draw[color=uququq] (0.8,0.12) node {$Xp$};
%%\fill [color=uququq] (1,1.04) circle (1.5pt);
%%\draw[color=uququq] (1.22,0.95) node {$Yp$};
\fill [color=uququq] (0.69,0.72) circle (1.5pt);
\draw[color=uququq] (0.82,0.7) node {$Yp$};
\fill [color=qqqqff] (0,0) circle (1.5pt);

%% Tangens
\draw[color=uququq] (1.27,1) node {$T=(1|t)$};
\fill [color=qqqqff] (1,1.05) circle (1.5pt);


\draw(0.20,0.09) node {$\varphi$};
\end{scriptsize}
\end{tikzpicture}\par
}%% END Command \einheitskreisT


\newcommand{\miniEinheitskreis}{
\tikzset{graphSkalierung/.style={xscale=2,yscale=2}}
\bbwGraph{-1.5}{1.5}{-1.5}{1.5}{
\bbwFuncC{ sqrt(4-\x*\x)}{-2:2}{lightgray}
\bbwFuncC{-sqrt(4-\x*\x)}{-2:2}{lightgray}
}
\tikzset{graphSkalierung/.style={xscale=1,yscale=1}}
}%% end newcommand miniEinheitskreis

