Skip to main content
Bounty Awarded with 50 reputation awarded by Rmano
deleted 2107 characters in body
Source Link
Qrrbrbirlbel
  • 130.5k
  • 9
  • 277
  • 524

The following solution definesext.topaths.arcthrough library from my tikz-extensions package has been created from this answer and provied a to path arc through key that expects one coordinate (including the () as it may preceeded with + or ++).

The solution provides two styles:As an argument, arc through also accepts clockwise and counter clockwise (default).

  • arc through ccw draws a counter-clockwise arc and
  • arc through cw draws a clockwise arc.

The point that is given as an argument to both styles is used to calculate the radius. The arc is not necessary drawn through this pointspoint, the circlecircle on which the arc lies only goes tothrough this point. This This makes it possible to draw the rest of said circle without the need to give another coordinate. (The name arc on circle that goes through would probably be a better name for the stylesthis …)

The coordinate arc through center is defined after the to path and can be used for later reference (as long as no other arc through is drawnused again, of course).

\documentclass[tikz]{standalone} \makeatletter \tikzset{ @arc through/.style 2 args={ to path={ \pgfextra \pgfextract@process\pgf@tostart{\tikz@scan@one@point\pgfutil@firstofone(\tikztostart)\relax}% \pgfextract@process\pgf@tothrough{\tikz@scan@one@point\pgfutil@firstofone#1}% \pgfextract@process\pgf@totarget{\tikz@scan@one@point\pgfutil@firstofone(\tikztotarget)\relax}% \pgfextract@process\pgf@topointMidA{\pgfpointlineattime{.5}{\pgf@tostart}{\pgf@tothrough}}% \pgfextract@process\pgf@topointMidB{\pgfpointlineattime{.5}{\pgf@totarget}{\pgf@tothrough}}% \pgfextract@process\pgf@tocenter{% \pgfpointintersectionoflines{\pgf@topointMidA} {\pgfmathrotatepointaround{\pgf@tothrough}{\pgf@topointMidA}{90}} {\pgf@topointMidB}{\pgfmathrotatepointaround{\pgf@tothrough}{\pgf@topointMidB}{90}}}% \pgfcoordinate{arc through center}{\pgf@tocenter}% \pgfpointdiff{\pgf@tocenter}{\pgf@tostart}% \pgfmathveclen@{\pgfmath@tonumber\pgf@x}{\pgfmath@tonumber\pgf@y}% \edef\pgf@toradius{\pgfmathresult pt} \pgfmathanglebetweenpoints{\pgf@tocenter}{\pgf@tostart}% \let\pgf@tostartangle\pgfmathresult \pgfmathanglebetweenpoints{\pgf@tocenter}{\pgf@totarget}% \let\pgf@toendangle\pgfmathresult \ifdim\pgf@tostartangle pt>\pgf@toendangle pt\relax \pgfmathsetmacro\pgf@tostartangle{\pgf@tostartangle-360}% \fi #2%  \pgfmathsetmacro\pgf@toendangle\usetikzlibrary{\pgf@toendangle-360}% \fi \endpgfextra arc [radius=+\pgf@toradius, start angle=\pgf@tostartangle, end angle=\pgf@toendangle] \tikztonodes }}, arc through ccw/ext.style={@arc through={#1}{\iffalse}}, arc through cw/topaths.style={@arc through={#1}{\iftrue}}, arcthrough} \makeatother \begin{document} \begin{tikzpicture} \coordinate\coordinate[label=above right:$A$] (A) at ( 3, 1); \coordinate (B) at ( 1, 2); \coordinate (C) at (-2,-2); \draw[ultra thick, draw=blue, fill=blue!50] (A) to[arc through ccw=(B)] (C) -- (arc through center) -- cycle; \foreach \p in {A,B,C, arc through center} \fill[red] (\p) circle(2pt); \end{tikzpicture} \begin{tikzpicture} \coordinate\coordinate[label=above:$B$] (A) at ( 3, 1); \coordinate (B) at ( 1, 2); \coordinate[label=below \coordinateleft:$C$]  (C) at (-2,-2);   \draw[ultra thick, draw=green, fill=green!50]  (B) to[arc through ccw=through={clockwise,(A)}] (C)  -- (arc through center) -- cycle; \draw[ultra thick, draw=blue,  fill=blue!50]   (B) to[arc through cw= through=(A)]  (C)  -- (arc through center) -- cycle; \foreach \p in {A,B,C, arc through center}  \fill[red] (\p) circle(2pt);circle[radius=2pt]; \end{tikzpicture} \end{document} 

enter image description here

The following solution defines a to path arc through that expects one coordinate (including the () as it may preceeded with + or ++).

The solution provides two styles:

  • arc through ccw draws a counter-clockwise arc and
  • arc through cw draws a clockwise arc.

The point that is given as an argument to both styles is used to calculate the radius. The arc is not necessary drawn through this points, the circle on which the arc lies only goes to this point. This makes it possible to draw the rest of said circle without the need to give another coordinate. (The name arc on circle that goes through would probably be a better name for the styles …)

The coordinate arc through center is defined after the to path and can be used for later reference (as long as no other arc through is drawn).

\documentclass[tikz]{standalone} \makeatletter \tikzset{ @arc through/.style 2 args={ to path={ \pgfextra \pgfextract@process\pgf@tostart{\tikz@scan@one@point\pgfutil@firstofone(\tikztostart)\relax}% \pgfextract@process\pgf@tothrough{\tikz@scan@one@point\pgfutil@firstofone#1}% \pgfextract@process\pgf@totarget{\tikz@scan@one@point\pgfutil@firstofone(\tikztotarget)\relax}% \pgfextract@process\pgf@topointMidA{\pgfpointlineattime{.5}{\pgf@tostart}{\pgf@tothrough}}% \pgfextract@process\pgf@topointMidB{\pgfpointlineattime{.5}{\pgf@totarget}{\pgf@tothrough}}% \pgfextract@process\pgf@tocenter{% \pgfpointintersectionoflines{\pgf@topointMidA} {\pgfmathrotatepointaround{\pgf@tothrough}{\pgf@topointMidA}{90}} {\pgf@topointMidB}{\pgfmathrotatepointaround{\pgf@tothrough}{\pgf@topointMidB}{90}}}% \pgfcoordinate{arc through center}{\pgf@tocenter}% \pgfpointdiff{\pgf@tocenter}{\pgf@tostart}% \pgfmathveclen@{\pgfmath@tonumber\pgf@x}{\pgfmath@tonumber\pgf@y}% \edef\pgf@toradius{\pgfmathresult pt} \pgfmathanglebetweenpoints{\pgf@tocenter}{\pgf@tostart}% \let\pgf@tostartangle\pgfmathresult \pgfmathanglebetweenpoints{\pgf@tocenter}{\pgf@totarget}% \let\pgf@toendangle\pgfmathresult \ifdim\pgf@tostartangle pt>\pgf@toendangle pt\relax \pgfmathsetmacro\pgf@tostartangle{\pgf@tostartangle-360}% \fi #2%  \pgfmathsetmacro\pgf@toendangle{\pgf@toendangle-360}% \fi \endpgfextra arc [radius=+\pgf@toradius, start angle=\pgf@tostartangle, end angle=\pgf@toendangle] \tikztonodes }}, arc through ccw/.style={@arc through={#1}{\iffalse}}, arc through cw/.style={@arc through={#1}{\iftrue}}, } \makeatother \begin{document} \begin{tikzpicture} \coordinate (A) at ( 3, 1); \coordinate (B) at ( 1, 2); \coordinate (C) at (-2,-2); \draw[ultra thick, draw=blue, fill=blue!50] (A) to[arc through ccw=(B)] (C) -- (arc through center) -- cycle; \foreach \p in {A,B,C, arc through center} \fill[red] (\p) circle(2pt); \end{tikzpicture} \begin{tikzpicture} \coordinate (A) at ( 3, 1); \coordinate (B) at ( 1, 2); \coordinate (C) at (-2,-2); \draw[ultra thick, draw=green, fill=green!50] (B) to[arc through ccw=(A)] (C) -- (arc through center) -- cycle; \draw[ultra thick, draw=blue,  fill=blue!50] (B) to[arc through cw= (A)] (C) -- (arc through center) -- cycle; \foreach \p in {A,B,C, arc through center} \fill[red] (\p) circle(2pt); \end{tikzpicture} \end{document} 

enter image description here

The ext.topaths.arcthrough library from my tikz-extensions package has been created from this answer and provied a arc through key that expects one coordinate (including the () as it may preceeded with + or ++).

As an argument, arc through also accepts clockwise and counter clockwise (default).

The point that is given as an argument is used to calculate the radius. The arc is not necessary drawn through this point, the circle on which the arc lies goes through this point. This makes it possible to draw the rest of said circle without the need to give another coordinate. (The name arc on circle that goes through would probably be a better name for this …)

The coordinate arc through center is defined after the to path and can be used for later reference (as long as no other arc through is used again, of course).

\documentclass[tikz]{standalone} \usetikzlibrary{ext.topaths.arcthrough} \begin{document} \begin{tikzpicture} \coordinate[label=above right:$A$] (A) at ( 3, 1); \coordinate[label=above:$B$] (B) at ( 1, 2); \coordinate[label=below left:$C$]  (C) at (-2,-2);   \draw[ultra thick, draw=green, fill=green!50]  (B) to[arc through={clockwise,(A)}] (C)  -- (arc through center) -- cycle; \draw[ultra thick, draw=blue, fill=blue!50]   (B) to[arc through=(A)]  (C)  -- (arc through center) -- cycle; \foreach \p in {A,B,C, arc through center}  \fill[red] (\p) circle[radius=2pt]; \end{tikzpicture} \end{document} 
replaced http://tex.stackexchange.com/ with https://tex.stackexchange.com/
Source Link

This solution uses the same calculation algorithm as the one in JLDiazJLDiazansweranswer.

This solution uses the same calculation algorithm as the one in JLDiazanswer.

This solution uses the same calculation algorithm as the one in JLDiazanswer.

Source Link
Qrrbrbirlbel
  • 130.5k
  • 9
  • 277
  • 524

The following solution defines a to path arc through that expects one coordinate (including the () as it may preceeded with + or ++).

It avoids

  • tkz-euclide or similar solutions that uses a separated path (which makes it impossible to use the arc as part of a path;
  • the calc library and instead uses PGF’s already present macros \pgfpointlineattime and \pgfpointintersectionofline as well as \pgfmathrotatepointaround and \pgfmathanglebetweenpoints.

The solution provides two styles:

  • arc through ccw draws a counter-clockwise arc and
  • arc through cw draws a clockwise arc.

The point that is given as an argument to both styles is used to calculate the radius. The arc is not necessary drawn through this points, the circle on which the arc lies only goes to this point. This makes it possible to draw the rest of said circle without the need to give another coordinate. (The name arc on circle that goes through would probably be a better name for the styles …)

The coordinate arc through center is defined after the to path and can be used for later reference (as long as no other arc through is drawn).

This solution uses the same calculation algorithm as the one in JLDiazanswer.

Code

\documentclass[tikz]{standalone} \makeatletter \tikzset{ @arc through/.style 2 args={ to path={ \pgfextra \pgfextract@process\pgf@tostart{\tikz@scan@one@point\pgfutil@firstofone(\tikztostart)\relax}% \pgfextract@process\pgf@tothrough{\tikz@scan@one@point\pgfutil@firstofone#1}% \pgfextract@process\pgf@totarget{\tikz@scan@one@point\pgfutil@firstofone(\tikztotarget)\relax}% \pgfextract@process\pgf@topointMidA{\pgfpointlineattime{.5}{\pgf@tostart}{\pgf@tothrough}}% \pgfextract@process\pgf@topointMidB{\pgfpointlineattime{.5}{\pgf@totarget}{\pgf@tothrough}}% \pgfextract@process\pgf@tocenter{% \pgfpointintersectionoflines{\pgf@topointMidA} {\pgfmathrotatepointaround{\pgf@tothrough}{\pgf@topointMidA}{90}} {\pgf@topointMidB}{\pgfmathrotatepointaround{\pgf@tothrough}{\pgf@topointMidB}{90}}}% \pgfcoordinate{arc through center}{\pgf@tocenter}% \pgfpointdiff{\pgf@tocenter}{\pgf@tostart}% \pgfmathveclen@{\pgfmath@tonumber\pgf@x}{\pgfmath@tonumber\pgf@y}% \edef\pgf@toradius{\pgfmathresult pt} \pgfmathanglebetweenpoints{\pgf@tocenter}{\pgf@tostart}% \let\pgf@tostartangle\pgfmathresult \pgfmathanglebetweenpoints{\pgf@tocenter}{\pgf@totarget}% \let\pgf@toendangle\pgfmathresult \ifdim\pgf@tostartangle pt>\pgf@toendangle pt\relax \pgfmathsetmacro\pgf@tostartangle{\pgf@tostartangle-360}% \fi #2% \pgfmathsetmacro\pgf@toendangle{\pgf@toendangle-360}% \fi \endpgfextra arc [radius=+\pgf@toradius, start angle=\pgf@tostartangle, end angle=\pgf@toendangle] \tikztonodes }}, arc through ccw/.style={@arc through={#1}{\iffalse}}, arc through cw/.style={@arc through={#1}{\iftrue}}, } \makeatother \begin{document} \begin{tikzpicture} \coordinate (A) at ( 3, 1); \coordinate (B) at ( 1, 2); \coordinate (C) at (-2,-2); \draw[ultra thick, draw=blue, fill=blue!50] (A) to[arc through ccw=(B)] (C) -- (arc through center) -- cycle; \foreach \p in {A,B,C, arc through center} \fill[red] (\p) circle(2pt); \end{tikzpicture} \begin{tikzpicture} \coordinate (A) at ( 3, 1); \coordinate (B) at ( 1, 2); \coordinate (C) at (-2,-2); \draw[ultra thick, draw=green, fill=green!50] (B) to[arc through ccw=(A)] (C) -- (arc through center) -- cycle; \draw[ultra thick, draw=blue, fill=blue!50] (B) to[arc through cw= (A)] (C) -- (arc through center) -- cycle; \foreach \p in {A,B,C, arc through center} \fill[red] (\p) circle(2pt); \end{tikzpicture} \end{document} 

Output

enter image description here

enter image description here