13

This example shows to draw some extra curve after the points by trial and error method.

Is there a specific tikz command to do it?

\documentclass{standalone}
\usepackage{tikz}

\begin{document}
%
\begin{tikzpicture}
%
\coordinate (n_3) at (1,1);
\coordinate (h_1) at (1.5,3);
%dots
\fill[blue] (n_3) circle (2pt);
\fill[blue] (h_1) circle (2pt);
%Left curve
\draw (n_3) to [bend right=5](h_1);
\draw (n_3) -- ++(-0.2,-0.5);
\draw (h_1) -- ++(0.1,0.5);
%
\end{tikzpicture}
%
\end{document}

Blue dots are used to draw the curve. Now how to extend the curve after the blue dots?

doncherry
  • 54,637
sandu
  • 7,950

3 Answers3

16

Using shorten > = <negative length> and shorten < = <negative length> will extend the curve with curved line segments. If the distances are short, and the curvature is small, this might be all you need, however, as Altermundus pointed out, if your curvature is large, the line will not pass through the defined points any more.

\documentclass[border=5mm]{standalone}
\usepackage{tikz}

\begin{document}
%
\begin{tikzpicture}
%
\coordinate (n_3) at (1,1);
\coordinate (h_1) at (3,1.5);
%dots
\fill[blue] (n_3) circle (2pt);
\fill[blue] (h_1) circle (2pt);
%Left curve
\draw [shorten >=-0.4cm,shorten <=-0.4cm] (n_3) to [bend right=5](h_1);
%
\end{tikzpicture}
%
\end{document}
Jake
  • 232,450
  • Bravo!! I was wrong because without [border=5mm] the picture is wrong. I think the bounding box is wrong. – Alain Matthes Jun 05 '12 at 06:32
  • @Altermundus: Yes, shorten doesn't affect the bounding box. I'm not sure if this is a bug or a feature... – Jake Jun 05 '12 at 06:36
  • 2
    @Jake The problem with the bounding box in this case is more important than the problem here : http://tex.stackexchange.com/questions/58292/a-line-of-length-textwidth-in-tikz/58304#58304 because the dimensions are sometimes larger. – Alain Matthes Jun 05 '12 at 07:04
  • @Jake The method doesn't work if you use [bend right=70] the points are not on the curve. I have also a problem in this case because I need to change the nodes. – Alain Matthes Jun 05 '12 at 07:20
  • @Jake shorten does not extend the curve with straight line segments tangential to the ends of your curve but I think the curve is drawn between to others points but I don't know how the point are choiced. – Alain Matthes Jun 05 '12 at 07:27
  • @Altermundus: You're right. I've edited my answer – Jake Jun 05 '12 at 07:30
  • Hopefully there's a better way than shorten >=-1cm by now? I used a dirty fix for the bounding box issue: \draw [shorten >=-1cm] (A) -- (B) node [inner sep=1cm] {}; or placing phantom{blabla} inside the node also has the effect of extending the bounding box, but it's less elegant. – PatrickT Mar 30 '21 at 01:38
8

Update

With [bend right=70] I need to adapt the nodes used at the end but the result is correct

\documentclass{article}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}

\coordinate (n_3) at (1,1);
\coordinate (h_1) at (1.5,3);

\fill[blue] (n_3) circle (2pt);
\fill[blue] (h_1) circle (2pt);

\draw (n_3) to [bend right=70] 
                node[pos=0,sloped,minimum width=.8cm] (n_3) {} 
                node[pos=1,sloped,minimum width=.8cm] (h_1) {}
                (h_1) ;
 \draw (n_3.center) --  (n_3.west);  
 \draw (h_1.center) --  (h_1.west);     
\end{tikzpicture}

\end{document} 

enter image description here

Actually with shorten and [bend right=70] we get

enter image description here

In other cases, with simple curves, I prefer Jake's answer but my first try with shorten was not efficient because I kept \documentclass{standalone} so I searched another way.

\documentclass{article}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}

\coordinate (n_3) at (1,1);
\coordinate (h_1) at (1.5,3);

\fill[blue] (n_3) circle (2pt);
\fill[blue] (h_1) circle (2pt);

\draw (n_3) to [bend right=5] 
                node[pos=0,sloped,minimum width=.8cm] (n_3) {} 
                node[pos=1,sloped,minimum width=.8cm] (h_1) {}
                (h_1) ;
 \draw (n_3.center) --  (n_3.west);  
 \draw (h_1.center) --  (h_1.east);     
\end{tikzpicture}

\end{document} 

enter image description here

Alain Matthes
  • 95,075
3

Here is another solution:

\documentclass[border=5mm]{standalone}
\usepackage{tikz}

\begin{document}
%
\begin{tikzpicture}
%
\coordinate (n_3) at (1,2);
\coordinate (h_1) at (3,1.5);
%dots
\fill[blue] (n_3) circle (2pt);
\fill[blue] (h_1) circle (2pt);
%Left curve
\path  (n_3) to [bend right=10]coordinate[pos=1.5](end) coordinate[pos=-0.5](begin)(h_1)--(end);
\draw (begin) -- (n_3) to [bend right=10] (h_1) -- (end);
\end{tikzpicture}
%
\end{document}

enter image description here

rpapa
  • 12,350