2

Given two lines, I want to connect both of them in a way, such that the connecting line is smooth. For example consider the following picture:

\documentclass{article}
\usepackage{graphicx}
\usepackage{tikz}
\usetikzlibrary{calc}
\usetikzlibrary{arrows}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}
\coordinate (v1) at (0,0);
\coordinate (v2) at (2,0);
\coordinate (v3) at (4,2);
\coordinate (v4) at (4,4);
\draw[fill, black] (v1) circle[radius=1pt];
\draw[fill, black] (v2) circle[radius=1pt];
\draw[fill, black] (v3) circle[radius=1pt];
\draw[fill, black] (v4) circle[radius=1pt];
\draw (v1)--(v2);
\draw (v3)--(v4);
\draw (2,2) circle(2);
\end{tikzpicture}
\end{document}

I am actually just interested in the quarter of the circle that connects the two lines. But I am having troubles

  1. Removing the other 75% of the circle and more importantly
  2. How to compute such a line for not perpendicular lines.

I tried using \draw[bend left], but this doesn't always yield a smooth connection. Does anyone know a better approach?

2
  • While code snippets are useful in explanations, it is always best to compose a fully compilable MWE that illustrates the problem including the \documentclass and the appropriate packages so that those trying to help don't have to recreate it. May 11, 2022 at 15:51
  • Thanks for pointing that out. It should work now.
    – samabu
    May 11, 2022 at 15:55

2 Answers 2

2

That is exactly what the controls command does: smoothly joining by Bezier curves, no matter these segments are perpendicular or not. Also, you can change the scalar factor .5, .8, 1.5, etc. to control shooting forces.

(A).. controls +(P) and +(Q) .. (B)

that is equivalent to

(A).. controls (A)+(P) and (B)+(Q) .. (B)

enter image description here

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
\path 
(0,0) coordinate (v1) node[below]{$v_1$}
(1,2) coordinate (v2) node[left]{$v_2$}
(4,2) coordinate (v3) node[right]{$v_3$}
(3,4) coordinate (v4) node[above]{$v_4$}
;
\draw (v1)--(v2) (v3)--(v4);

\draw[red] (v2).. controls +($.5*(v2)-.5*(v1)$) and +($.8*(v3)-.8*(v4)$) .. (v3);  

\foreach \p in {v1,v2,v3,v4}
\fill (\p) circle(2pt);
\end{tikzpicture}
\begin{tikzpicture}
\path 
(0,0) coordinate (v1) node[below]{$v_1$}
(2,0) coordinate (v2) node[below]{$v_2$}
(4,2) coordinate (v3) node[right]{$v_3$}
(4,4) coordinate (v4) node[above]{$v_4$}
;
\draw (v1)--(v2) (v3)--(v4);
    
\draw[blue] (v2).. controls +($.5*(v2)-.5*(v1)$) and +($.8*(v3)-.8*(v4)$) .. (v3);  
    
\foreach \p in {v1,v2,v3,v4}
\fill (\p) circle(2pt);
\end{tikzpicture}
\end{document}
4
  • Thank you! This looks really good! I just have a short question about the scaling factors. Is there a rule of thumb why you chose for example in the blue line 0.5 and 0.8?
    – samabu
    May 12, 2022 at 7:07
  • @samabu the scaling factors affect to the shooting forces from two line. I recommend reading Section 74.3 Curves in the pgfmanual.pdf ctan.org/pkg/pgf
    – Black Mild
    May 12, 2022 at 7:16
  • I added more explanation on Bezier curves. Hope that helps! en.wikipedia.org/wiki/B%C3%A9zier_curve
    – Black Mild
    May 12, 2022 at 7:21
  • Ah, now I get it. Thank you very much!
    – samabu
    May 12, 2022 at 10:55
2

You can use the keys out and in. The take an argument (an angle) and work essentially like bend left, but you can choose the angle that works best on both ends.

\documentclass[11pt,a4paper]{amsart}
\usepackage{graphicx}
\usepackage{tikz}
\usetikzlibrary{calc}
\usetikzlibrary{arrows}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}
\coordinate (v1) at (0,0);
\coordinate (v2) at (2,0);
\coordinate (v3) at (4,2);
\coordinate (v4) at (4,4);
\draw[fill, black] (v1) circle[radius=1pt];
\draw[fill, black] (v2) circle[radius=1pt];
\draw[fill, black] (v3) circle[radius=1pt];
\draw[fill, black] (v4) circle[radius=1pt];
\draw (v1)--(v2);
\draw (v3)--(v4);
\draw (2,0) to [out=0, in=270] (4,2);
\end{tikzpicture}
\end{document}

In this particular case, as you noted, you can also insert only an arc of circle. For example, the output of the above example is the same if the last line of the TikZ picture is replaced with

\draw (2,0) arc [start angle=-90, end angle=0, radius=2];
2
  • Hello, thanks for pointing this out. For non-perpendicular lines I do not know how to compute the right angle. Do you know how to do that?
    – samabu
    May 11, 2022 at 16:03
  • @samabu If you want to connect two straight lines, I guess the correct angle can always be computed rather directly using inverse trigonometric functions and the coordinates of the lines. But I don't know how to compute it automatically with TikZ.
    – Vincent
    May 11, 2022 at 16:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .