0

I want to draw a curved line between two points but I can't define coordinates if I'm not using --. Is that deliberate or am I doing something wrong?

So, to explain better. If I use the following code:

\draw ($ (A) - (-0.5,0.5) $) -- ($ (A) - (5,10) $) coordinate[pos=0.4] (E);

I get a line using:

\draw[color=red] (0,0) -- (E.center);

But not if I use this (which I want):

\draw ($ (A) - (-0.5,0.5) $) to [out=270,in=0] ($ (A) - (5,10) $) coordinate[pos=0.4] (E);

Am I doing something wrong?

Complete code:

\usepackage{tikz}
\usetikzlibrary{decorations.shapes}
\usetikzlibrary{calc}
\usetikzlibrary{arrows.meta}
\title{TikZ-test}

\tikzset{decorate sep/.style 2 args=
{decorate,decoration={shape backgrounds,shape=circle,shape size=#1,shape sep=#2}}}

\begin{tikzpicture}
\node (A) at (-5,-0.25){};
\node (B) at (5,-0.25){};
\node (C) at (-1.2,1){};
\node (D) at (1.2,1){};

\draw[line width=1mm] (A.center) -- (B.center);

\draw[line width=1mm] (C) -- (D);
\draw[line width=1mm] (0,1) -- (0,2);
\draw[line width=1mm] (A) -- (-1,0) -- (1,0) -- (B);
\draw[line width=1mm,fill=white] (0,0) circle (1cm);

\draw ($ (A) - (-0.5,0.5) $) to [out=270,in=0] ($ (A) - (5,10) $) coordinate[pos=0.4] (E);

\draw ($ (B) - (0.5,0.5) $) to [out=270,in=0] ($ (B) - (5,10) $);

\draw[color=red] (0,0) -- (E.center);
\end{tikzpicture}
  • Welcome to TeX.SE! The pos syntax does not work with arbitrary curves, but you can, of course, use decorations.markings to make it work. – marmot Jan 11 at 16:37
  • By adding \usetikzlibrary{decorations.shapes} I assume? – Jonathan Persson Jan 11 at 16:40
1

The pos syntax does not work with arbitrary curves, but you can, of course, use decorations.markings to make it work.

\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{calc}
\usetikzlibrary{decorations.markings}
\begin{document}
\begin{tikzpicture}[mark pos/.style args={#1 with #2}{postaction={decorate,
decoration={markings,mark=at position #1 with {#2}}}}]
\node (A) at (-5,-0.25){};
\node (B) at (5,-0.25){};
\node (C) at (-1.2,1){};
\node (D) at (1.2,1){};

\draw[line width=1mm] (A.center) -- (B.center);

\draw[line width=1mm] (C) -- (D);
\draw[line width=1mm] (0,1) -- (0,2);
\draw[line width=1mm] (A) -- (-1,0) -- (1,0) -- (B);
\draw[line width=1mm,fill=white] (0,0) circle (1cm);

\draw[mark pos=0.4 with {\coordinate (E);}] ($ (A) - (-0.5,0.5) $) to [out=270,in=0] ($ (A) - (5,10) $);

\draw ($ (B) - (0.5,0.5) $) to [out=270,in=0] ($ (B) - (5,10) $);

\draw[color=red] (0,0) -- (E.center);
\end{tikzpicture}
\end{document}

enter image description here

NOTE: You could also to place the nodes inside the path when you use pos=0.5. (For straight lines -- you can be more sloppy.). decorations.markings always works, also for more complicated paths (unless the path has high curvature).

0

You made a simple syntax error.

It is possible to place coordinates or nodes in a To Path operation but for this you must place them between the two coordinates of the operation (See page 161 of Tikz manual 3.1).

I quote:

Nodes on to–paths. It is possible to add nodes to the paths constructed by a to operation. To do so, you specify the nodes between the to keyword and the coordinate (if there are options to the to operation, these come first). The effect of (a) to node {x} (b) (typically) is the same as if you had written (a) --node {x} (b), namely that the node is placed on the to.

screenshot

\documentclass[border=5mm]{standalone} 
\usepackage{tikz} 
\usetikzlibrary{decorations.shapes}
\usetikzlibrary{calc}
\usetikzlibrary{arrows.meta}
\begin{document} 



%\title{TikZ-test}

\tikzset{decorate sep/.style 2 args=
{decorate,decoration={shape backgrounds,shape=circle,shape size=#1,shape sep=#2}}}

\begin{tikzpicture}
\node (A) at (-5,-0.25){};
\node (B) at (5,-0.25){};
\node (C) at (-1.2,1){};
\node (D) at (1.2,1){};

\draw[line width=1mm] (A.center) -- (B.center);

\draw[line width=1mm] (C) -- (D);
\draw[line width=1mm] (0,1) -- (0,2);
\draw[line width=1mm] (A) -- (-1,0) -- (1,0) -- (B);
\draw[line width=1mm,fill=white] (0,0) circle (1cm);

\draw ($ (A) - (-0.5,0.5) $) to [out=270,in=0] coordinate[pos=0.4] (E)($ (A) - (5,10) $) ;

\draw ($ (B) - (0.5,0.5) $) to [out=270,in=0] ($ (B) - (5,10) $);

\draw[color=red] (0,0) -- (E.center);
\end{tikzpicture}

\end{document}

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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