[Tex/LaTex] How to invert a parabola bend in TikZ


Just a quick question. I'm trying to fill in a parabola shape in tikz. I've managed to make it work horizontally. However, when I do the same method vertically. There's a weird deformity that I can't solve. The image is below!


This is the code to create this image:





\begin{figure}[h] \label{Interesting_Pic}


    %Grid and outer layers 
    \draw[black, very thick] (4,-0.5) rectangle (9,4.5);
    \draw[black, very thick] (4.5,0) rectangle (8.5,4);
    \draw[step=5mm,black] (4.5,0) grid (8.5,4);
    %diagonal lines in corner 
    \draw[fill=lime] (4,-0.5) -- (4.5,0);
    \draw[fill=lime] (4,4.5) -- (4.5,4);
    \draw[fill=lime] (9,-0.5) -- (8.5,0);
    \draw[fill=lime] (8.5,4) -- (9,4.5);
    %Labels lines in corners 
        (4,-0.5) node [left] {$A_{4}$}
        (4,4.5) node [left] {$A_{1}$}
        (9,-0.5) node [right] {$A_{3}$}
        (9,4.5) node [right] {$A_{2}$};
    %Draw parabola bends
    \draw[bend left,->] (4.5,0) to node [auto] {} (8.5,0);
    \draw[bend right,->] (4.5,0) to node [auto] {} (4.5,4);
    \draw[bend left,->] (8.5,0) to node [auto] {} (8.5,4);
    \draw[bend left,->] (8.5,4) to node [auto] {} (4.5,4);
    %Colour in parabola areas
    \draw[fill=white] (8.5,0) -- (4.5,0) parabola bend (6.5,0.6) (8.5,0);
    \draw[fill=white] (8.5,0) -- (8.5,4) to node (7.1,2) {} (8.5,0);
    \draw[fill=white] (4.5,0) parabola bend (5.1,2) (4.5,4) -- (4.5,0);
    \draw[fill=white] (4.5,4) -- (8.5,4) parabola bend (6.5,3.4) (4.5,4);

\caption{An interesting diagram...}


I tried two different methods for the left and right sides, (as seen by the %right side and %left side lines at the bottom) but neither worked correctly.

I am trying to do the same thing that I did with the curves at the top and bottom, but doing the same method inverts the parabola bend (as seen on the left hand side). Does anyone know of a way to make the left and right side the same as the top and bottom?

Cheers! 🙂

edit: Added entire code, so it will create the image above!

Best Answer

You've used bend left/bend right earlier in the drawing, use that again, and it works fine. For example \draw[fill=white] (8.5,0) to[bend right] (4.5,0);

This image shows output of your original code, with some style changes. The blue arrow is made with bend left, the dashed red line with parabola bend. They're not 100% equivalent, but very close.

enter image description here

Speaking of the arrow tips, do you want to make them larger (they're hardly visible)? Or remove them altogether?

Some other comments:

  • The hyperref package should in general be loaded late, see Which packages should be loaded after hyperref instead of before?
  • As I mentioned in a comment, you need to place the \label after the \caption, or cross references wont work, see Why does an environment's label have to appear after the caption?
  • Your scope environment doesn't really do anything useful.
  • I added \centering before \begin{tikzpicture}
  • In the block starting with %Draw Pin-Cushion Distortion, you have an empty node in each line, which isn't needed.
  • When you draw the lines between the corners, you also have fill=lime. Did you intend to fill any region with lime, or is that just something you've forgotten to remove?

That said, here is a complete example. Using named coordinates can be useful sometime, I rewrote the code to show one method using such. Of course, you don't have to use it.

enter image description here




\begin{tikzpicture} %detector on right (Pin-Cushion distorted)

\begin{scope}[every label/.style={font=\footnotesize}]
    % coordinates at outer corners
    \coordinate [label=left:$A_1$]  (A1) at (4,4.5);
    \coordinate [label=right:$A_2$] (A2) at (9,4.5);
    \coordinate [label=right:$A_3$] (A3) at (9,-0.5);
    \coordinate [label=left:$A_4$]  (A4) at (4,-0.5);

    % inner corners, relative to outer corners
    \path (A1) ++(0.5,-0.5)  coordinate (B1);
    \path (A2) ++(-0.5,-0.5) coordinate (B2);
    \path (A3) ++(-0.5,0.5)  coordinate (B3);
    \path (A4) ++(0.5,0.5)   coordinate (B4);

    %Grid and outer layers of detector 
    \draw[black, very thick] (A4) rectangle (A2);
    \draw[black, very thick] (B4) rectangle (B2);
    \draw[step=5mm,black] (B4) grid (B2);

    %Anode wiring 
    \foreach \i in {1,...,4}
       \draw (A\i) -- (B\i);

    % draw and fill bendy lines
    \draw[bend left,fill=white]  (B4) to (B3);
    \draw[bend right,fill=white] (B4) to (B1);
    \draw[bend left,fill=white]  (B3) to (B2);
    \draw[bend left,fill=white]  (B2) to (B1);

\caption{An interesting diagram...}