3

I would like to make the following diagram: enter image description here

How could I make it? I find it difficult create the hyperbola's arc.

Y_gr
  • 3,322

1 Answers1

6

Although your picture suggests otherwise, I will assume that the “bow” is in fact an arc of constant radius.

Ignoring the dot and dot* style for a minute (they both place a dot and a label at the coordinate we define later while the latter also draws the dashed lines to the axes), an arc of a constant radius can be drawn very simple using basic geometry, the calc library and the intersection of syntax (that is a wrapper for the intersection cs) to find the center of the radius.

I hope the comments in the code are helpful enough.

I have also added a Bézier curve (?) with the control point C' which is found in the same matter as C (the center of the arc) but lies on the tangent DA.

The coordinate M is found early on with ($(A)!.5!(B)$).

Code

\documentclass[tikz,convert=false]{standalone}
\usetikzlibrary{calc}
\tikzset{
  every label/.append style={inner sep=+.1667em},
  dot/.style={
    label={[
        label distance=+0pt,
        shape=circle,
        fill=black,
        inner sep=+0pt,
        outer sep=+0pt,
        minimum size=+2pt,
        label={#1}
      ]center:}},
  dot*/.style={
    dot={#1},
    append after command={
      \pgfextra
        \pgfinterruptpath
          \let\myTikzlastnode\tikzlastnode
          \draw[thin,dashed] (0,0 |- \myTikzlastnode) node[left] {$P_{\myTikzlastnode}$} -| (0,0 -| \myTikzlastnode) node[below] {$Q_{\myTikzlastnode}$};
        \endpgfinterruptpath
      \endpgfextra
    }
  }
}
\begin{document}
\begin{tikzpicture}[thick]
\draw[<->] (0,6) node[left]  {$P$} |- node[below left] {$O$}
           (6,0) node[below] {$Q$};

\path (1,3)   coordinate[dot*=below left:$A$]       (A)
    ++(120:1) coordinate[dot =$D$] (D)
      (4,1)   coordinate[dot*=below left:$B$] (B);
;

\draw let
        % let's save D, A and B in other macros so that we can acess their x and y value separately
        \p1=(D),
        \p2=(A),
        \p3=(B),
        % then the middle between A and B is
        \p{M}=($(\p2)!.5!(\p3)$),
        % while the angles from D to A is
        \n{1-2}={atan2(\x2-\x1,\y2-\y1)},
        % a line orthogonal to the line between A and B has the angle of
        \n{ortho 2-3}={90+atan2(\x3-\x2,\y3-\y2)},
        % which means that the center of a circle through A and B that has the tangent DA lies at the intersection of
        \p{C}=(intersection of A--[shift=(90+\n{1-2}:10)]A and \p{M}--[shift={(\n{ortho 2-3}:10)}]\p{M}),
        % the radius is then simply (we can use either A or B to calculate the radius
        \n{radius}={veclen(\x{C}-\x3,\y{C}-\y3)},
        % the end angle at B is then also
        \n{end angle}={atan2(\x3-\x{C},\y3-\y{C})},
        %!
        %! for the Bézier curve:
        \p{C'}=(intersection of A--[shift=(\n{1-2}:10)]A and \p{M}--[shift={(\n{ortho 2-3}+180:10)}]\p{M})
      in % great, let's draw it, first the tangent
       (D) -- (A)
       % then the arc
       arc[radius=\n{radius}, start angle=\n{1-2}-90, end angle=\n{end angle}]
       % let's append another tangent at the end of the arc
       -- ++(\n{end angle}+90:1)
       % and while we're at we can also save the center of the arc in a coordiante M
%       (\p{C}) coordinate[dot=above:$C$] (C)               %?
       (\p{M}) coordinate[dot*=above right:$M$] (M)
       % let's draw the connection from A to B
       (A)--(B)
       %!
       %! for the Bézier curve
%       (\p{C'}) coordinate[dot=left:$C'$] (C') % for later %?
      ;
%\draw[thin,dotted] (A) -- (C) -- (B) -- (C') -- cycle;     %?
%\draw[thin,blue]   (A) .. controls (C') .. (B);            %?
\end{tikzpicture}
\end{document}

Output

enter image description here

This image is the same as above but shows the center of the radius C, the Bézier curve as well as its control point C' and has been compiled with the lines marked with %? not commented out.

Qrrbrbirlbel
  • 119,821
  • @Qrrbebirlbel Firstly, thank you very much. Secondly, I don't know whether your diagram is similar to mine. My diagram has a linear part which connects the points A and B and in the half of this line there is the M point (this is why AM=MB). – Y_gr Jul 02 '13 at 15:54
  • 1
    @giannis I have updated my answer with the “plain” version of your image (the arc is still not a hyperbola though). The other image shows the previous version with M lying in the middle of A and B. – Qrrbrbirlbel Jul 02 '13 at 16:10
  • I was trying to recompile my tex and now it shows ! Package pgfkeys Error: I do not know the key '/tikz/ label distance', to whic h you passed '+0pt', and I am going to ignore it. Perhaps you misspelled it.

    See the pgfkeys package documentation for explanation. Type H for immediate help. Is there any chance to clash with any other package?

    – Y_gr Jun 09 '16 at 20:24
  • 1
    @giannis Append a % to the sixth line: i.e. label={[% – Qrrbrbirlbel Jun 09 '16 at 20:27
  • still not the same result as yours, unfortunately. – Y_gr Jun 09 '16 at 20:47
  • @giannis Ah, yes, I see. That is because when PGF v3 came out, the syntax of atan2 was changed, see Q244569. – Qrrbrbirlbel Jun 09 '16 at 21:02
  • which one should I change. I'm afraid I can't understand it from the Q244569. – Y_gr Jun 10 '16 at 18:48
  • @giannis You need to swap the arguments of every atan2 in the code. – Qrrbrbirlbel Jun 10 '16 at 18:57