4

My problem is, that when I want to draw a curve I don't know where to put the control points. Is there a method for calculating the coordinates? For example I want to draw this curve here and I don't know where are the controls. I can make a guess but that's not exact.

The curve

Thank you for your help!

  • 1
    You can use Hobby's algorithm (or the hobby package, which implements it) to specify only the tangent directions and let the computer come up with reasonable control points. – Charles Staats Dec 12 '15 at 16:20
  • 1
    The OP is asking HOW to calculate the control points of a Beizer. Which is more of a maths question, like this: math.stackexchange.com/questions/1037222/… – William 'Ike' Eisenhauer Dec 12 '15 at 19:56
  • @William'Ike'Eisenhauer, where did the OP mention Beizer? – CroCo Dec 12 '15 at 21:04
  • Sorry if I did not mention, but yes I need the method of the calculations. Since you are all LaTeX users I thought you can write me the method. By the way @CroCo, your solution was quite good, I liked it. – ostal123 Dec 12 '15 at 21:43
  • The thing is, I don't know how many of us calculate the control points. Probably some of the specialists do, but I'm betting that I'm not the only one who does not. I asked this question about how to figure out values for control points. But note that I was explicitly not asking how to calculate precise values but, rather, how to think about them intuitively. Probably the information there is of little interest, but may explain why asking elsewhere may be more fruitful! – cfr Dec 13 '15 at 2:57
6

Since this is a curve. You can choose three points and connect them.

(A) to [out=angle1,in=angle2] (B);

where A and B are points and angle1 and angle2 control the way curved line enters and leaves a point.

enter image description here

This is the code

\documentclass[border={10}]{standalone}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}
\coordinate (A)  at (0,0);
\coordinate (B)  at (0,-1);
\coordinate (C)  at (1,0);

\draw[very thick] (A) to [out=225,in=180,looseness=1.5] (B);
\draw[very thick] (B) to [out=0,in=270]               (C);

\end{tikzpicture}

\end{document}

enter image description here


Edit: Regarding the in and out, I will show you the way the curved line leaves A point and the rest will be clear. Regarding looseness, it curves the line more. Try to change it to see its effect.

enter image description here

Optional: This is the code for the above picture

\documentclass[border={10}]{standalone}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}
[%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
        Circ/.style={circle,fill=blue,thick,
                      inner sep=0pt,minimum size=1mm}
]%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\coordinate (A)  at (0,0);
\coordinate (B)  at (0,-1);
\coordinate (C)  at (1,0);

\draw[very thick] (A) to [out=225,in=180,looseness=1.5] (B);
\draw[very thick] (B) to [out=0,in=270]                 (C);


\draw[red] (-.8,0) -- (1.5,0);
\draw[red] ( 0,.5) -- (0,-1.3);

\node [Circ,label={[xshift=-5mm]30:A}]             at (A) {};
\node [Circ,label={[xshift=-5mm,yshift=-5mm]30:B}] at (B) {};
\node [Circ,label={[xshift=-5mm]30:C}]             at (C) {};

\draw [green] (.1,0) arc (0:225:.1) node[xshift=-2.5mm,yshift=.15mm] {\tiny out} ;

\end{tikzpicture}

\end{document}
  • Thanks that's useful, but I have a question: how did you calculate the "in" and "out" angles and what does "looseness" do? – ostal123 Dec 12 '15 at 18:37
  • @ostal123, please see the update. Also, I've changed looseness to 1.5 to make it more smooth and curved. – CroCo Dec 12 '15 at 20:35
  • @ostal123, regarding the actual angles, since you didn't specify any thing about the curve, I've just tried to mimic your picture. – CroCo Dec 12 '15 at 20:41
  • Alright, I understand now. Thanks for helping me. – ostal123 Dec 12 '15 at 20:46
  • @ostal123, you are welcome. – CroCo Dec 12 '15 at 20:48
2

You can use the ..controls (coordinate) and (coordinate) .. syntax to draw Bezier curves.

\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
  \coordinate (A) at (.35,.75);
  \coordinate (B) at (.85,.75);
  \coordinate (C1) at (-.4,.1);
  \coordinate (C2) at (.86,.12);
  \draw[red] (A) .. controls (C1) and (C2) .. (B);
  \node[red,draw,fill,inner sep=1pt] at (A) {};
  \node[red,draw,fill,inner sep=1pt] at (B) {};
\end{tikzpicture}
\end{document}

I put your image in the background to emphasize the analogy.

enter image description here

  • Please, let me know how did you calculate the coordinates of controls. – ostal123 Dec 12 '15 at 18:41
  • 1
    I think it will be helpful to show the code for loading the picture and drawing on it. Just suggestion so that the OP can modify the parameters accordingly . – CroCo Dec 12 '15 at 21:03
  • @ostal123 I determined the control point by mere trial and error, i.e. I varied them until it fit. – Henri Menke Dec 13 '15 at 18:05
  • 2
    @CroCo You can find the instructions on how to draw on an image with TikZ in this question. – Henri Menke Dec 13 '15 at 18:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.