With the following code:



        \tkzInit[xmin=-1, xmax=3, ymin=-1,ymax=3]
        \tkzDefPoints{.5/2/P_1, 2.5/0/P_2, 1.5/1/M,2/1.5/A}

        \tkzDrawX[noticks, label={\(\operatorname{Re}(x) \)}]
        \tkzDrawY[noticks, label={\(\operatorname{Im}(x) \)}]

        \tkzDrawPoints[fill=black, size=1mm](P_1,P_2,M)
        \tkzFct[domain=-1:3, color=red, thick]{x-.5}
        \draw (P_1) -- (P_2);
        \tkzLabelPoints[above right](P_1,P_2)

        \tkzText[color=black](1.5,3){\(|z-z_1|\leq|z-z_2| \)}

I'm getting:

enter image description here

I wanted to add a fade like this:

enter image description here

but I can't have the fade to be in the right angle.

How can I get this kind of fade, fadding to white?


This is a tkz-euclid solution.


    % set working area
    \tkzInit[xmin=-1, xmax=3, ymin=-1, ymax=3]
    \clip (-1.5,-1.5) rectangle (4,4); % more precise than \tkzClip[space=1]
    % define points
    \tkzDefPoints{.5/2/P_1, 2.5/0/P_2}
    % shade half plane
    \tkzFillPolygon[draw=white,top color=white,bottom color=red,middle color=white,shading angle=45](A1,A2,A3,A4)
    % draw axes
    \tkzDrawX[noticks, label={\(\operatorname{Re}(x)\)}]
    \tkzDrawY[noticks, label={\(\operatorname{Im}(x)\)}]
    % draw segments
    % mark angles
    % mark points
    \tkzDrawPoints[fill=black, size=1mm](P_1,P_2,M)
    \tkzLabelPoints[above right](P_1,P_2)
    % extra text

enter image description here


This is in principle very simple but tkz-euclide seems to mess up things a bit. One can just use a shading angle, which can, of course, be computed by TikZ.

  \begin{tikzpicture}[anchor=center,declare function={f(\x)=\x-0.5;
      \draw[-latex] (-1.5,0) -- (3.5,0) node[below left]{$\re z$};
      \draw[-latex] (0,-1.5) -- (0,3.5) node[below left]{$\im z$};;
      \path foreach \X/\Y/\L/\P in {.5/2/P_1/45, 2.5/0/P_2/45, 1.5/1/M/0}
      {(\X,\Y) coordinate[label=\P:$\L$] (\L)};
      \begin{scope}[on background layer]
      \shade let \p1=({xmin},{f(xmin)}),\p2=({xmax},{f(xmax)}),
      \n1={atan2(\y2-\y1,\x2-\x1)} in 
       [left color=white,right color=red,middle color=white,shading angle=\n1]
       (\p1) -- (\p2)  --  ($(\p2)!2cm!-90:(\p1)$) -- ($(\p1)!2cm!90:(\p2)$)
      \draw[red,thick] plot[variable=\x,domain=xmin:xmax] ({\x},{f(\x)});
      \draw (P_1) -- (P_2);
      \node[anchor=south,red] at (1.5,3) {$|z-z_1|\leq|z-z_2| $};

enter image description here

  • 3
    I like your answer, and the correction of \re(x) and \im(x) :). – manooooh Mar 23 at 2:44

You may rotate the shading area to the x-axis, shade, then rotate back.

enter image description here

\coordinate[label=above right:$P_1$] (P1) at (.5,2);
\coordinate[label=above right:$P_2$] (P2) at (2.5,0);
\coordinate[label=right:$M$] (M) at (1.5,1);
\coordinate (A) at (2,1.5);

\shade[top color=white,bottom color=red!50,rotate around={45:(.5,0)}] 
(\a,0) rectangle (\b,.8);
\draw[-latex] (-1,0)--(3.5,0) node[below]{\rm{Re}$(x)$};
\draw[-latex] (0,-1)--(0,3.5) node[left]{\rm{Im}$(x)$};

\draw (P1)--(P2);
\draw[red,thick] plot[domain=-.5:3] (\x,{\x-.5});
\foreach \p in {P1,P2,M}
\fill (\p) circle(1pt);
\node at (1.8,3.2){$|z-z_1|\leq|z-z_2|$};
  • 1
    You don't need tkz-euclide just to mark a right angle. You can (since version 3.1 of TikZ) do it with the standard angles library like this pic[draw]{right angle=P1--M--A}. – Kpym Mar 23 at 7:29
  • @Kymp: yes, that's also a convernient way – Black Mild Mar 23 at 9:12

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.