\input{Figs/Klein.Base.tikz};


%Convex parameter on PQ
\pgfmathparse{0.2}\let\tx\pgfmathresult;

%Convex parameter on PQ
\pgfmathparse{0.7}\let\ty\pgfmathresult;

%X=X(tx)
\coordinate (X) at ($(P)!\tx!(Q)$);

\pgfmathparse{(1-\tx)*\px+\tx*\qx}\let\xx\pgfmathresult;
\pgfmathparse{(1-\tx)*\py+\tx*\qy}\let\xy\pgfmathresult;


\fill (X) circle(1pt) node [above] {$X$};

%Y=Y(ty)
\coordinate (Y) at ($(P)!\ty!(Q)$);

\fill (Y) circle(1pt) node [above] {$Y$};



%Vary \ty, and calculate Klein distance
\pgfmathparse{0.1}\let\tleft\pgfmathresult;
\pgfmathparse{0.9}\let\tright\pgfmathresult;
\pgfmathparse{0.5}\let\tm\pgfmathresult;

\pgfmathparse{1.5*\R}\let\tpos\pgfmathresult;

\coordinate (OO) at (2*\R,0);

\pgfmathparse{3}\let\tfact\pgfmathresult;
\pgfmathparse{1.5}\let\ffact\pgfmathresult;

\draw
   [
      variable=\t,
      domain=\tleft:\tright,
   ]
   plot
   (
      { \tpos+\tfact*\t},
      { \ffact*ln(\t/(1-\t)}
   );

\draw[-Latex]
   ($(\tpos-0.1,0)$)
   --
   ($(\tpos+3.1*\tright,0)$)
   node [right] {$t$};

\pgfmathparse{\ffact*ln(\tleft/(1-\tleft))}\let\fleft\pgfmathresult;
\pgfmathparse{\ffact*ln(\tright/(1-\tright))}\let\fright\pgfmathresult;

%Lower and upper points on f(t)-axis
\coordinate (TopLeft) at (\tpos,\fleft);
\coordinate (BotLeft) at (\tpos,\fright);

%Lower and upper points on f(t)-axis
\coordinate (TopRight) at (\tpos+\tfact*\tright,\fleft);
\coordinate (BotRight) at (\tpos+\tfact*\tright,\fright);

\draw[-Latex]
   (TopLeft)
   --
   (BotLeft)
   node [above] {$f(t)$};


\pgfmathparse{\ffact*ln(\tx/(1-\tx))}\let\fx\pgfmathresult;
\pgfmathparse{\ffact*ln(\ty/(1-\ty))}\let\fy\pgfmathresult;

%(t,f) point for X
\coordinate (TX) at (\tpos+\tfact*\tx,\fx);
\fill (TX) circle(1pt) node[right] {$t_x$};

%(t,f) point for Y
\coordinate (TY) at (\tpos+\tfact*\ty,\fy);
\fill (TY) circle(1pt) node[right] {$t_y$};


\coordinate (TXLeft)  at ($(BotLeft)!(TX)!(TopLeft)$);
\coordinate (TXRight) at ($(BotRight)!(TX)!(TopRight)$);

%Convex parameter on left point
\pgfmathparse{-0.2}\let\tdraw\pgfmathresult;

\coordinate (TXLeft)  at ($(TXLeft)!\tdraw!(TXRight)$);
%Draw horisontal line through left (t,f)
\draw[dotted]
   (TXLeft)
   --
   (TXRight);
   
\coordinate (TYLeft)  at ($(BotLeft)!(TY)!(TopLeft)$);
\coordinate (TYRight) at ($(BotRight)!(TY)!(TopRight)$);

\coordinate (TYLeft)  at ($(TYLeft)!\tdraw!(TYRight)$);
%Draw horisontal line through left (t,f)
\draw[dotted]
   (TYLeft)
   --
   (TYRight);


\draw[very thin,-Latex]
  ($(TXLeft)!0.5!(TYLeft)$)
  --
  (TXLeft);
  
\draw[very thin,-Latex]
  ($(TXLeft)!0.5!(TYLeft)$)
  --
  (TYLeft);

\node [left] at ($(TXLeft)!0.5!(TYLeft)$) {$d_K$};
