5

I need a color gradient to follow a sum function in both the vertical and horizontal direction. In the figure only the horizontal sum function (the bottom line in the figure) is shown. What I need is a color gradient that follows the path coming from the MMF (The red colored trapez coming from the MMF rectangle).

Any help will be highly appreciated

enter image description here

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning}


\begin{document}

    \begin{tikzpicture}
    \newcommand\XOBJ{3}
    \newcommand\YOBJ{10}
    \newcommand\scale{0.3}

    \path[use as bounding box] (0,-1) rectangle (11.5,12);

    \node (rect) at (\XOBJ,\YOBJ) (OBJ) [draw,thick,minimum width=1.7cm,minimum height=1cm] {OBJ};
    \node (MMF) [rectangle, draw,thick,xshift = 2.5cm,minimum width=2.5cm,minimum height=0.5cm,right of = OBJ] {MMF};

    \filldraw [red,opacity=0.2] ([yshift=-2pt]OBJ.north east) --([yshift=2pt]OBJ.south east) -- ([yshift=2pt]MMF.south west) -- ([yshift=-2pt]MMF.north west) -- ([yshift=-2pt]OBJ.north east);

    \filldraw [red,opacity=0.2] ([yshift=2pt]MMF.south east) -- ([yshift=-2pt]MMF.north east) -- (10,11) -- (10,9) -- ([yshift=2pt]MMF.south east);

    \node (N1) [circle,draw, right of = MMF,xshift = 1.2cm,yshift = 0.2cm ] {};
    \node (N2) [circle,draw, right of = N1,yshift = 0.1cm,xshift = 0.01] {};
    \node (N3) [circle,draw, below right = 0.1 cm and 0.255cm of N1 ] {};
    \node (N5) [circle,draw, below right = -0.7cm and -0.2cm of N1 ] {};
    \node (N6) [circle,draw, below right = 0.6cm and -0.2cm of N1 ] {};
    \node (N7) [circle,draw, below right = 0.6cm and 0.7cm of N1 ] {};

    \draw[scale=0.5,domain=-1:4,smooth,variable=\x,red] plot ({\x+17},{\scale*sin(deg(\x+4))+17}) node[anchor=east,xshift = -2.5cm ] {Wave 1};
    \draw[scale=0.5,domain=-1:4,smooth,variable=\x,red] plot ({\x+17},{\scale*cos(deg(2*\x+3))+15.5}) node[anchor=east,xshift = -2.5cm ] {Wave 2};
    \draw[scale=0.5,domain=-1:4,smooth,variable=\x,red] plot ({\x+17},{\scale*cos(deg(3*\x))+14}) node[anchor=east,xshift = -2.5cm ] {Wave 3};

    \draw[scale=0.5,domain=-1:4,smooth,variable=\x,red] plot ({\x+17},{\scale*sin(deg(\x+4))+\scale*cos(deg(2*\x+3)) + \scale*cos(deg(3*\x))     +12}) node[anchor=east,xshift = -2.5cm ] {Sum};

    \end{tikzpicture}
\end{document}
3

Here is a slightly different proposal in which the shading really depends on the sum of the three waves. Notice that I adjusted the shape of the right wedge a bit such that the shading really is synchronized with the plots.

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning,backgrounds}


\begin{document}

    \begin{tikzpicture}
    \newcommand\XOBJ{3}
    \newcommand\YOBJ{10}
    \newcommand\scale{0.3}

    \path[use as bounding box] (0,-1) rectangle (11.5,12);

    \node (rect) at (\XOBJ,\YOBJ) (OBJ) [draw,thick,minimum width=1.7cm,minimum height=1cm] {OBJ};
    \node (MMF) [rectangle, draw,thick,xshift = 2.5cm,minimum width=2.5cm,minimum height=0.5cm,right of = OBJ] {MMF};

    \filldraw [red,opacity=0.2] ([yshift=-2pt]OBJ.north east) --([yshift=2pt]OBJ.south east) -- ([yshift=2pt]MMF.south west) -- ([yshift=-2pt]MMF.north west) -- ([yshift=-2pt]OBJ.north east);


    \node (N1) [circle,draw, right of = MMF,xshift = 1.2cm,yshift = 0.2cm ] {};
    \node (N2) [circle,draw, right of = N1,yshift = 0.1cm,xshift = 0.01] {};
    \node (N3) [circle,draw, below right = 0.1 cm and 0.255cm of N1 ] {};
    \node (N5) [circle,draw, below right = -0.7cm and -0.2cm of N1 ] {};
    \node (N6) [circle,draw, below right = 0.6cm and -0.2cm of N1 ] {};
    \node (N7) [circle,draw, below right = 0.6cm and 0.7cm of N1 ] {};

    \draw[scale=0.5,domain=-1:4,smooth,variable=\x,red] plot ({\x+17},{\scale*sin(deg(\x+4))+17}) node[anchor=east,xshift = -2.5cm ] {Wave 1};
    \draw[scale=0.5,domain=-1:4,smooth,variable=\x,red] plot ({\x+17},{\scale*cos(deg(2*\x+3))+15.5}) node[anchor=east,xshift = -2.5cm ] {Wave 2};
    \draw[scale=0.5,domain=-1:4,smooth,variable=\x,red] plot ({\x+17},{\scale*cos(deg(3*\x))+14}) node[anchor=east,xshift = -2.5cm ] {Wave 3};

    \draw[scale=0.5,domain=-1:4,smooth,variable=\x,red] plot ({\x+17},{\scale*sin(deg(\x+4))+\scale*cos(deg(2*\x+3)) + \scale*cos(deg(3*\x))     +12}) node[anchor=east,xshift = -2.5cm ] {Sum};

\tikzset{declare function={mysum(\x)=
\scale*sin(deg(\x+4))+\scale*cos(deg(2*\x+3)) + \scale*cos(deg(3*\x))     +12;
}}


    \begin{scope}[on background layer]
     \clip  ([yshift=2pt]MMF.south east) -- ([yshift=-2pt]MMF.north east) --
     (11,11) -- (11,9) -- cycle;
     \foreach \x in {-1,-0.9,...,4}
     {
%    \pgfmathsetmacro{\X}{mysum(\x)}
%    \typeout{\x : \X}
     \pgfmathsetmacro{\X}{60*(mysum(\x)-11.4)}
     \pgfmathsetmacro{\Y}{60*(mysum(\x+0.1)-11.4)}
%    \typeout{\X,\Y}
     \shade[left color=red!\X,right color=red!\Y] ({8.5+\x/2},9) rectangle
     ({8.5+\x/2+0.1},11);
     }
%     \filldraw      [red,opacity=0.2] (MMF.south east|-10,9) rectangle (10,11);
    \end{scope}

    \end{tikzpicture}
\end{document}

enter image description here

As you can see, the shading is darker at x at which the sum is larger.

  • nothing less than perfect :) – Jesper H Mar 19 '18 at 14:53
  • @JesperH Oooh! Definitely didn't understand your original question then. Thanks marmot – caverac Mar 19 '18 at 16:37
4

Something like this?

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning}


\begin{document}

    \begin{tikzpicture}
    \newcommand\XOBJ{3}
    \newcommand\YOBJ{10}
    \newcommand\scale{0.3}

    \path[use as bounding box] (0,-1) rectangle (11.5,12);

    \node (rect) at (\XOBJ,\YOBJ) (OBJ) [draw,thick,minimum width=1.7cm,minimum height=1cm] {OBJ};
    \node (MMF) [rectangle, draw,thick,xshift = 2.5cm,minimum width=2.5cm,minimum height=0.5cm,right of = OBJ] {MMF};

    \filldraw [red,opacity=0.2] ([yshift=-2pt]OBJ.north east) --([yshift=2pt]OBJ.south east) -- ([yshift=2pt]MMF.south west) -- ([yshift=-2pt]MMF.north west) -- ([yshift=-2pt]OBJ.north east);

    \filldraw [left color=red, right color=blue!30!white,opacity=0.2] ([yshift=2pt]MMF.south east) -- ([yshift=-2pt]MMF.north east) -- (10,11) -- (10,9) -- ([yshift=2pt]MMF.south east);

    \node (N1) [circle,draw, right of = MMF,xshift = 1.2cm,yshift = 0.2cm ] {};
    \node (N2) [circle,draw, right of = N1,yshift = 0.1cm,xshift = 0.01] {};
    \node (N3) [circle,draw, below right = 0.1 cm and 0.255cm of N1 ] {};
    \node (N5) [circle,draw, below right = -0.7cm and -0.2cm of N1 ] {};
    \node (N6) [circle,draw, below right = 0.6cm and -0.2cm of N1 ] {};
    \node (N7) [circle,draw, below right = 0.6cm and 0.7cm of N1 ] {};

    \draw[scale=0.5,domain=-1:4,smooth,variable=\x,red] plot ({\x+17},{\scale*sin(deg(\x+4))+17}) node[anchor=east,xshift = -2.5cm ] {Wave 1};
    \draw[scale=0.5,domain=-1:4,smooth,variable=\x,red] plot ({\x+17},{\scale*cos(deg(2*\x+3))+15.5}) node[anchor=east,xshift = -2.5cm ] {Wave 2};
    \draw[scale=0.5,domain=-1:4,smooth,variable=\x,red] plot ({\x+17},{\scale*cos(deg(3*\x))+14}) node[anchor=east,xshift = -2.5cm ] {Wave 3};

    \draw[scale=0.5,domain=-1:4,smooth,variable=\x,red] plot ({\x+17},{\scale*sin(deg(\x+4))+\scale*cos(deg(2*\x+3)) + \scale*cos(deg(3*\x))     +12}) node[anchor=east,xshift = -2.5cm ] {Sum};

    \end{tikzpicture}
\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.