[Tex/LaTex] dynamic clipping plane with TikZ

tikz-pgf

i have a problem with TikZ. I'd like to draw a dynamic clipping-plane. the top of the red area is dynamic, the blue one should be the same high/level but much larger dimension… to seperate optical from the red area. some ideas?

Update I added another picture to make my point clear. the blue square should fit perfect on top of the red frustum. it should be dynamic, so if i change the hight of the frustum, the blue square will move as well. My problem is that the height of the red frustum is a part of the ray from the viewpoint to the bottom. if it possible to give a parameter for height wich fit in the perspektive and the ray, that would solve the problem as well i think.

\begin{tikzpicture}[scale=1]
\usetikzlibrary{calc}
        %%% Parameter %%%
        \pgfmathsetmacro{\frameHeight}{8}
        \pgfmathsetmacro{\frameWidth}{0.92}
        \pgfmathsetmacro{\frameDepth}{0.87}
        \pgfmathsetmacro{\viewpointDepth}{0.5}
        \pgfmathsetmacro{\viewpointCentering}{0.5}
        \pgfmathsetmacro{\projectionHeight}{0.36}
        \pgfmathsetmacro{\projectionWidth}{0.96}
        \pgfmathsetmacro{\projectionDepth}{0.07}
            % Fluchtpunkte
        \coordinate (F1) at (30:50cm);
        \coordinate (F2) at (150:50cm);
            % Eckpunkte
        \coordinate (P1) at (0cm,0cm);                  % v U
        \coordinate (P2) at (0cm,\frameHeight);     % v O
        \coordinate (P3) at ($(F1)!\frameDepth!(P1)$);  % h U
        \coordinate (P4) at ($(F1)!\frameDepth!(P2)$);  % h O
        \coordinate (P5) at ($(F2)!\frameWidth!(P1)$);  
        \coordinate (P6) at ($(F2)!\frameWidth!(P2)$);
        \coordinate (P7) at (intersection cs: first line={(P5) -- (F1)}, second line={(P3) -- (F2)});
        \coordinate (P8) at (intersection cs: first line={(P6) -- (F1)}, second line={(P4) -- (F2)});
        \coordinate (P9) at ($(P2)!\viewpointDepth!(P4)$);
        \coordinate (P10) at (intersection cs: first line={(P9) -- (F2)}, second line={(P6) -- (P8)});
            % Sichtfeld
        \coordinate (A) at ($(P5)!\projectionWidth!(P1)$);
        \coordinate (B) at ($(P1)!\projectionWidth!(P5)$);
        \coordinate (C) at ($(A)!\projectionDepth!(F1)$);   
        \coordinate (D) at (intersection cs: first line={(C) -- (F2)}, second line={(B) -- (F1)});  
        \coordinate (V) at ($(P9)!\viewpointCentering!(P10)$);
            % Nutzfläche Schnitt
        \coordinate (E) at ($(A)!\projectionHeight!(V)$);
        \coordinate (F) at (intersection cs: first line={(E) -- (F2)}, second line={(V) -- (B)});
        \coordinate (G) at (intersection cs: first line={(E) -- (F1)}, second line={(V) -- (C)});
        \coordinate (H) at (intersection cs: first line={(F) -- (F1)}, second line={(V) -- (D)});
            % nutz Sichtfeld Ebene
        \coordinate (P11) at ($(E)$); %({(E)--(F2)}:2);
        \coordinate (P12) at ($(F)$);
        \coordinate (P13) at ($(G)$);
        \coordinate (P14) at ($(H)$);
            % real Sichtfeld Ebene
        \coordinate (P15) at (0, -1);
        \coordinate (P16) at ($(P15)!0.115!(F2)$);
        \coordinate (P17) at ($(F1)!0.835!(P15)$);
        \coordinate (P18) at (intersection cs: first line={(P16) -- (F1)}, second line={(P17) -- (F2)});
        %Linien
        \draw[rounded corners, draw=black!80, fill=yellow!80, opacity=0.5] (P15) -- (P16) -- (P18) -- (P17)  -- cycle;
            % Tiefe / Verlauf
        \begin{scope}[opacity=0.2]
        \shade[top color=gray!70,bottom color=gray!5] (P1) -- (P3) -- (P7) -- (P5);
        \shade[right color=gray!70,left color=gray!5] (P5) -- (P6) -- (P8) -- (P7);
        \shade[left color=gray!70,right color=gray!5] (P7) -- (P3) -- (P4) -- (P8);
        \end{scope}
            % Sichtfeld der Kamera
        \fill [red!80, opacity=0.4] (A) -- (B) -- (D) -- (C);
        \begin{scope}[thin, dashed, red]%thick, dashed, fill=red!80, opacity=1]
            \draw (A) -- (V);
            \draw (B) -- (V);
            \draw (C) -- (V);
            \draw (D) -- (V);
        \end{scope}
        \begin{scope}[red]
            \draw (A) -- (E);
            \draw (B) -- (F);
            \draw (D) -- (H);
            \draw (C) -- (G);
        \end{scope}
        \draw [thin, red] (A) -- (B) -- (D) -- (C) -- (A);
        \draw [thin, red] (E) -- (F) -- (H) -- (G) -- (E);
        %\draw [thick, red!80] (
        \begin{scope}[red!80, opacity=0.1]
            \fill (A) -- (B) -- (F) -- (E);
            \fill (C) -- (A) -- (E) -- (G);
            \fill (D) -- (C) -- (G) -- (H);
            \fill (B) -- (D) -- (H) -- (F);
        \end{scope}
        \draw[rounded corners, draw=black!80, fill=blue!80, opacity=0.5] (P11) -- (P12) -- (P14) -- (P13) -- cycle;
            % Frame
        \begin{scope}[thin, opacity=0.6]
            \draw (P1) -- (P3) -- (P4) -- (P2) -- (P1) ;
            \draw (P1) -- (P5) -- (P6) -- (P2) -- (P1) ;
            \draw (P2) -- (P6) -- (P8) -- (P4) -- (P2) ;
            \draw (P3) -- (P7) -- (P8) -- (P4) -- (P3) ;
            \draw (P1) -- (P5) -- (P7) -- (P3) -- (P1) ;
        \end{scope}
        \draw[thin,dashed] (P9) -- (P10);
        % Verbindungspunkte
        \foreach \i in {1,2,...,10}
            {
             \shade[shading=ball, ball color=black!80] (P\i) circle (0.05em) node[above right] {}; %\tiny \i};
            }
        \foreach \i in {A, B,...,H}
            {
            \shade[shading=ball, ball color=red] (\i) circle (0.05em) node[above right] {}; %\tiny \i};
            }
        %Beschriftung
        %\draw[fill=red] (V) circle (0.25em) node[above right] {\tiny Viewpoint};
        \shade[shading=ball, ball color=red] (V) circle (0.25em) node[above right] {\tiny Betrachtungspunkt};
        \draw[] (4.75,0.8) to[out=90,in=-90] (0.75,2);
        \draw (4.75,0.5) node[] {\footnotesize nutzbares Sichtfeld};
        \draw[] (-5.5,4.3) to[out=90,in=-90] (-0.5,4.5);
        \draw (-5.5,4) node[] {\footnotesize unterer Schwellwert};
        \draw[] (-5.5,0.8) to[out=90,in=-90] (-3,1.4);
        \draw (-5.5,0.5) node[] {\footnotesize oberer Schwellwert};
\end{tikzpicture}

enter image description here
enter image description here

Best Answer

Is this what you want (changing the \projectionHeight value will move the frustum and the plane together)?

\documentclass{report}
\usepackage[T1]{fontenc}


\usepackage{pgfplots}
\usetikzlibrary{intersections}


\begin{document}

\begin{tikzpicture}[scale=1]
\usetikzlibrary{calc}
        %%% Parameter %%%
        \pgfmathsetmacro{\frameHeight}{8}
        \pgfmathsetmacro{\frameWidth}{0.92}
        \pgfmathsetmacro{\frameDepth}{0.87}
        \pgfmathsetmacro{\viewpointDepth}{0.5}
        \pgfmathsetmacro{\viewpointCentering}{0.5}
        \pgfmathsetmacro{\projectionHeight}{0.5}
        \pgfmathsetmacro{\projectionWidth}{0.96}
        \pgfmathsetmacro{\projectionDepth}{0.07}
            % Fluchtpunkte
        \coordinate (F1) at (30:50cm);
        \coordinate (F2) at (150:50cm);
            % Eckpunkte
        \coordinate (P1) at (0cm,0cm);                  % v U
        \coordinate (P2) at (0cm,\frameHeight);     % v O
        \coordinate (P3) at ($(F1)!\frameDepth!(P1)$);  % h U
        \coordinate (P4) at ($(F1)!\frameDepth!(P2)$);  % h O
        \coordinate (P5) at ($(F2)!\frameWidth!(P1)$);  
        \coordinate (P6) at ($(F2)!\frameWidth!(P2)$);
        \coordinate (P7) at (intersection cs: first line={(P5) -- (F1)}, second line={(P3) -- (F2)});
        \coordinate (P8) at (intersection cs: first line={(P6) -- (F1)}, second line={(P4) -- (F2)});
        \coordinate (P9) at ($(P2)!\viewpointDepth!(P4)$);
        \coordinate (P10) at (intersection cs: first line={(P9) -- (F2)}, second line={(P6) -- (P8)});
            % Sichtfeld
        \coordinate (A) at ($(P5)!\projectionWidth!(P1)$);
        \coordinate (B) at ($(P1)!\projectionWidth!(P5)$);
        \coordinate (C) at ($(A)!\projectionDepth!(F1)$);   
        \coordinate (D) at (intersection cs: first line={(C) -- (F2)}, second line={(B) -- (F1)});  
        \coordinate (V) at ($(P9)!\viewpointCentering!(P10)$);
            % Nutzfläche Schnitt
        \coordinate (E) at ($(A)!\projectionHeight!(V)$);
        \coordinate (F) at (intersection cs: first line={(E) -- (F2)}, second line={(V) -- (B)});
        \coordinate (G) at (intersection cs: first line={(E) -- (F1)}, second line={(V) -- (C)});
        \coordinate (H) at (intersection cs: first line={(F) -- (F1)}, second line={(V) -- (D)});
            % nutz Sichtfeld Ebene
        \coordinate (P11) at ($(E)$); %({(E)--(F2)}:2);
        \coordinate (P12) at ($(F)$);
        \coordinate (P13) at ($(G)$);
        \coordinate (P14) at ($(H)$);
            % real Sichtfeld Ebene
        \coordinate (P15) at (0, -1);
        \coordinate (P16) at ($(P15)!0.115!(F2)$);
        \coordinate (P17) at ($(F1)!0.835!(P15)$);
        \coordinate (P18) at (intersection cs: first line={(P16) -- (F1)}, second line={(P17) -- (F2)});
        \coordinate (P15') at (0, \projectionHeight*\frameHeight);
        \coordinate (P16') at ($(P15')!0.115!(F2)$);
        \coordinate (P17') at ($(F1)!0.835!(P15')$);
        \coordinate (P18') at (intersection cs: first line={(P16') -- (F1)}, second line={(P17') -- (F2)});
        %Linien
        \draw[rounded corners, draw=black!80, fill=yellow!80, opacity=0.5] (P15) -- (P16) -- (P18) -- (P17)  -- cycle;
        \draw[rounded corners, draw=black!80, fill=cyan!80, opacity=0.5] (P15') -- (P16') -- (P18') -- (P17')  -- cycle;
            % Tiefe / Verlauf
        \begin{scope}[opacity=0.2]
        \shade[top color=gray!70,bottom color=gray!5] (P1) -- (P3) -- (P7) -- (P5);
        \shade[right color=gray!70,left color=gray!5] (P5) -- (P6) -- (P8) -- (P7);
        \shade[left color=gray!70,right color=gray!5] (P7) -- (P3) -- (P4) -- (P8);
        \end{scope}
            % Sichtfeld der Kamera
        \fill [red!80, opacity=0.4] (A) -- (B) -- (D) -- (C);
        \begin{scope}[thin, dashed, red]%thick, dashed, fill=red!80, opacity=1]
            \draw (A) -- (V);
            \draw (B) -- (V);
            \draw (C) -- (V);
            \draw (D) -- (V);
        \end{scope}
        \begin{scope}[red]
            \draw (A) -- (E);
            \draw (B) -- (F);
            \draw (D) -- (H);
            \draw (C) -- (G);
        \end{scope}
        \draw [thin, red] (A) -- (B) -- (D) -- (C) -- (A);
        \draw [thin, red] (E) -- (F) -- (H) -- (G) -- (E);
        %\draw [thick, red!80] (
        \begin{scope}[red!80, opacity=0.1]
            \fill (A) -- (B) -- (F) -- (E);
            \fill (C) -- (A) -- (E) -- (G);
            \fill (D) -- (C) -- (G) -- (H);
            \fill (B) -- (D) -- (H) -- (F);
        \end{scope}
            % Frame
        \begin{scope}[thin, opacity=0.6]
            \draw (P1) -- (P3) -- (P4) -- (P2) -- (P1) ;
            \draw (P1) -- (P5) -- (P6) -- (P2) -- (P1) ;
            \draw (P2) -- (P6) -- (P8) -- (P4) -- (P2) ;
            \draw (P3) -- (P7) -- (P8) -- (P4) -- (P3) ;
            \draw (P1) -- (P5) -- (P7) -- (P3) -- (P1) ;
        \end{scope}
        \draw[thin,dashed] (P9) -- (P10);
        % Verbindungspunkte
        \foreach \i in {1,2,...,10}
            {
             \shade[shading=ball, ball color=black!80] (P\i) circle (0.05em) node[above right] {}; %\tiny \i};
            }
        \foreach \i in {A, B,...,H}
            {
            \shade[shading=ball, ball color=red] (\i) circle (0.05em) node[above right] {}; %\tiny \i};
            }
        %Beschriftung
        %\draw[fill=red] (V) circle (0.25em) node[above right] {\tiny Viewpoint};
        \shade[shading=ball, ball color=red] (V) circle (0.25em) node[above right] {\tiny Betrachtungspunkt};
        \draw[] (4.75,0.8) to[out=90,in=-90] (0.75,2);
        \draw (4.75,0.5) node[] {\footnotesize nutzbares Sichtfeld};
        \draw[] (-5.5,4.3) to[out=90,in=-90] (-0.5,4.5);
        \draw (-5.5,4) node[] {\footnotesize unterer Schwellwert};
        \draw[] (-5.5,0.8) to[out=90,in=-90] (-3,1.4);
        \draw (-5.5,0.5) node[] {\footnotesize oberer Schwellwert};
\end{tikzpicture}


\end{document}