3

I would like to join points (s) and (t) via arc. Could u help me to implement it?! I've tried it by such way \draw (s) arc (t); It is wrong! To say simply I need the correct arc without spreading over the first and second lines coinciding with defined path named as bloody arc.

\documentclass[12pt,a4paper]{article}
\usepackage{tikz}
\usepackage{rotating}
\usetikzlibrary{calc,intersections}
\tikzset{
HH/.style={thick}}

\def\scalefactor{2}

\begin{document}

\begin{tikzpicture}[scale=\scalefactor]
\draw[help lines] (0,0) grid (7,5);
\path[red,thick,name path= bloody arc]
  ([shift={(0:3)}]2,1) arc (0:90:3);
\draw[HH,name path=first line] (2,1)--(5,2);
\draw[HH,name path=second line] (2,1)--(6,5);

\path[red,name intersections={of=first line and bloody arc, by=s}];
\path[red,name intersections={of=second line and bloody arc, by=t}];
\draw[HH] (s)--(t);
% \draw (s) arc (t);
\end{tikzpicture}
\end{document}
percusse
  • 157,807
David
  • 361

3 Answers3

4

You could also use the calc library:

\documentclass[tikz, border=5]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc,intersections}
\tikzset{HH/.style={thick}}
\def\scalefactor{2}
\begin{document}
\begin{tikzpicture}[scale=\scalefactor]
\draw[help lines] (1,0) grid (7,5);
\draw[red,thick, name path=bloody arc]  ([shift={(0:3)}]2,1) arc (0:90:3);
\draw[HH, name path=first line] (2,1)--(5,2);
\draw[HH, name path=second line] (2,1)--(6,5);
\path[red,name intersections={of=first line and bloody arc, by=s}];
\path[red,name intersections={of=second line and bloody arc, by=t}];
\coordinate (u) at (2,1);
\draw [green] let \p1=($(s)-(u)$),\p2=($(t)-(u)$),\n1={atan2(\y1,\x1)},
\n2={atan2(\x2,\y2)} in (s) arc (\n1:\n2:3);
\end{tikzpicture}
\end{document}

enter image description here

But here is a circular arc around "to path" which (I think) does things correctly, but for speed uses some internal commands.

\documentclass[tikz, border=5]{standalone}
\usetikzlibrary{calc,intersections}
\makeatletter
\tikzset{%
  circular arc around/.style={
    to path={%
      \pgfextra{%
        \tikz@scan@one@point\pgf@process#1%
        \pgf@xa=-\pgf@x\pgf@ya=-\pgf@y
        \pgf@xb=-\pgf@x\pgf@yb=-\pgf@y
        \tikz@scan@one@point\pgf@process(\tikztostart)%
        \advance\pgf@xa by\pgf@x%
        \advance\pgf@ya by\pgf@y%
         \tikz@scan@one@point\pgf@process(\tikztotarget)%
       \advance\pgf@xb by\pgf@x%
       \advance\pgf@yb by\pgf@y%
       \pgfmathveclen{\pgf@xa}{\pgf@ya}\let\tikz@radius=\pgfmathresult%
       \pgfmathatantwo{\the\pgf@ya}{\the\pgf@xa}%
       \pgfmathMod@{\pgfmathresult}{360}%
       \let\tikz@angle@a=\pgfmathresult%
       \pgfmathatantwo{\the\pgf@yb}{\the\pgf@xb}%
       \pgfmathMod@{\pgfmathresult}{360}%
       \let\tikz@angle@b=\pgfmathresult%    
       \edef\tikz@to@arc@path{ arc(\tikz@angle@a:\tikz@angle@b:\tikz@radius pt) }\show\tikz@to@arc@path
      } \tikz@to@arc@path
    }  
  }
}
\begin{document}
\begin{tikzpicture}[scale=1/2]

\draw [help lines] (0,0) grid (8,8);
\coordinate (o) at (4,4);
\tikzset{shift=(o)}


\foreach \i in {0.5,1,...,3.5}
  \draw [very thick] (o) circle [radius=\i];

\foreach \i [evaluate={\a=rnd*45+\i;\b=\a+rnd*20+30;}] in {0,90,180,270}{
\coordinate  (p) at (\a:4);
\coordinate  (q) at (\b:4);

\fill [fill opacity=0.25] (o) -- (p) to [circular arc around=(o)] (q) -- cycle;

\foreach \c [count=\r from 1] in {red, yellow, pink, green, orange, purple, blue}{
 \coordinate (s) at ($(o)!\r*0.5cm!(p)$);
 \coordinate (t) at ($(o)!\r*0.5cm!(q)$);
 \draw [very thick,densely dotted, \c] (s) to [circular arc around=(o)] (t); 
}
}
\end{tikzpicture}
\end{document}

enter image description here

Mark Wibrow
  • 70,437
2

Using tkz-euclide

The accepted answer to the question What's the easiest way to draw the arc defined by three points in TikZ? demonstrates how to draw an arc using a center and two points, which is exactly what you try to achieve. However it uses the tkz-euclide package which is only documented in french at the moment, though an english manual will supposedly be released in the future.

Here's your code modified to draw the arc using \tkzDrawArc from tkz-euclide. Also, note that the arc slightly overlaps the original lines because the intersections are at the center of the lines.

Close up of first arc

\documentclass[12pt,a4paper]{article}
\usepackage{tikz}
\usepackage{tkz-euclide}
\usetkzobj{all}
\usetikzlibrary{calc,intersections}
\tikzset{HH/.style={thick}}

\def\scalefactor{2}

\begin{document}

\begin{tikzpicture}[scale=\scalefactor]
\draw[help lines] (0,0) grid (7,5);
\path[draw, red,thick,name path= bloody arc]
  ([shift={(0:3)}]2,1) arc (0:90:3);
\draw[HH,name path=first line] (2,1)--(5,2);
\draw[HH,name path=second line] (2,1)--(6,5);

\path[red,name intersections={of=first line and bloody arc, by=s}];
\path[red,name intersections={of=second line and bloody arc, by=t}];
\draw[HH] (s)--(t);
\path (2,1) coordinate (center); % Where the two lines intersect
\tkzDrawArc[HH,color=black](center,s)(t) % Draw arc counterclockwise from (s) to (t).
\end{tikzpicture}
\end{document}

Using Clipping

Alternatively, if you don't want to use tkz-euclide, you can use a clip path to restrict the arc to the area between the two lines. Sadly, you can't specify any other options on clipping paths, so you have to give the coordinates for the lines twice: once for clipping and once for actually drawing the two lines.

Close up of second arc

\documentclass[12pt,a4paper]{article}
\usepackage{tikz}
\usetikzlibrary{calc,intersections}
\tikzset{HH/.style={thick}}

\def\scalefactor{2}

\begin{document}

\begin{tikzpicture}[scale=\scalefactor]
    \draw[help lines] (0,0) grid (7,5);
    \begin{scope}
        \clip (6,5) -- (2,1) -- (5,2); % Only for clipping
        \path[red,draw,thick,name path= bloody arc]
            ([shift={(0:3)}]2,1) arc (0:90:3);
    \end{scope}
    \draw[HH] (6,5) -- (2,1)--(5,2); % Actually drawing the lines
\end{tikzpicture}
\end{document}
Fritz
  • 6,273
  • 31
  • 55
0

If you already know intersecting point between bloody arc and first/second line you can repeat bloody arc but clip it with the appropiate rectangle.

\documentclass[12pt,a4paper]{article}
\usepackage{tikz}
\usepackage{rotating}
\usetikzlibrary{calc,intersections}
\tikzset{
HH/.style={thick}}

\def\scalefactor{2}

\begin{document}

\begin{tikzpicture}[scale=\scalefactor]
\draw[help lines] (0,0) grid (7,5);
\draw[red,thick,name path= bloody arc]
  ([shift={(0:3)}]2,1) arc (0:90:3);
\draw[HH,name path=first line] (2,1)--(5,2);
\draw[HH,name path=second line] (2,1)--(6,5);

\path[red,name intersections={of=first line and bloody arc, by=s}];
\path[red,name intersections={of=second line and bloody arc, by=t}];
\draw[HH] (s)--(t);
\begin{scope}
\clip (s) rectangle (t);
\draw[green,thick,name path= bloody arc]
  ([shift={(0:3)}]2,1) arc (0:90:3);
\end{scope}
% \draw (s) arc (t);
\end{tikzpicture}
\end{document}

enter image description here

Ignasi
  • 136,588
  • Good idea, but this won't work if the points happen to be directly above each other. It only works in this special case because the arc doesn't protrude to the right of the lower point (s). – Fritz Aug 13 '14 at 16:19