弦の中心を中心とする半円

弦の中心を中心とする半円

を中心とする半円ノードが必要ですchord center。 配置はオプション で実現されますanchorが、外部の線は依然として に向けられています。 線を に向けることもcenter可能ですか?chord center

ムウェ

\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\usetikzlibrary{shapes.geometric}

\begin{tikzpicture}
\node [semicircle,draw,shape border rotate=180,anchor=chord center,outer sep=0,inner sep=0.2cm] (a) at (1,1) {};
\draw (0,0) -- (a);
\draw[densely dashed] (0,0) -- (1,1);
\end{tikzpicture}

\end{document}

ここに画像の説明を入力してください

答え1

新しいシェイプを定義する代わりに、その周囲に別の円ノードを配置したチートバージョンを示します。

semicircle centerこのため、外側のセップとは関係なく、常に弦の中央に配置されるシェイプにアンカーを追加します。

semicircle centerこれにより、外側のセップを変更せずにシェイプを配置できます。

次に、circle半円と同じ (外側の) 半径を持つ別のノードを追加します。これには半円と同じ名前が付けられますが、 が追加されます'

技術的には、シェイプ自体から半径を抽出することもできますが、throughライブラリを使用すると非常に簡単にできます。(atthroughポイント間の距離を測定し、それをminimum sizeノードの として設定します。)

コード

\documentclass[tikz]{standalone}
\usetikzlibrary{shapes.geometric, through}
\makeatletter
\pgfutil@namedef{pgf@anchor@semicircle@semicircle center}{%
  \pgfpointadd{\pgf@sh@reanchor{semicircle}{chord center}}{%
    \installsemicircleparameters\pgfpointpolar{\rotate+90}{\outersep}}}
\makeatother
\tikzset{
  circle around semi/.style={
    append after command={[every node/.code=]%
    node[at=(\tikzlastnode.semicircle center),
    circle through=(\tikzlastnode.apex), overlay, 
    anchor=center, name=\tikzlastnode', inner sep=+0pt, outer sep=+0pt,
    path only]{}}}}
\begin{document}

\begin{tikzpicture}[ultra thick]
\node [
  semicircle, circle around semi, draw,
  shape border rotate=180,
  anchor=semicircle center,
  inner sep=0.2cm
] (a) at (1,1) {};
\draw[red] (0,0) -- (a');
\end{tikzpicture}
\tikz\draw[ultra thick]
  (0,0) .. controls +(30:1) and +(135:2) .. (2,2)
  foreach[count=\i from 0, evaluate=\i as \c using \i/4*100]
    \pos in {.125, .333, .5, .75, .95}{
    node[fill=red!\c!blue, draw=blue!\c!red, fill, thin, sloped,
    semicircle, circle around semi, pos=\pos, anchor=semicircle center](@){}
    (@') foreach \ang in {0,15,...,359}{edge[thin] ++(\ang:.3)}
  };
\end{document}

出力

ここに画像の説明を入力してください

ここに画像の説明を入力してください

答え2

クリッピングが機能する可能性もあります (ただし、特定のケースでは機能しない可能性があり、半円内のテキストの配置を調整する必要があります)。

\documentclass{standalone}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}

\begin{scope}
\clip (0.5,1) rectangle +(1,-1);
\node [circle, draw, outer sep=0, inner sep=0.25cm] (a) at (1,1) {};
\end{scope}

\draw[line cap=rect] (a.east) -- (a.west);
\draw[red] (0,0) -- (a);

\end{tikzpicture}
\end{document}

ここに画像の説明を入力してください

答え3

私のコメントによると、この問題は次のように回避できる。\fill

コード

\documentclass[border=3mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric}
\colorlet{pagebackground}{yellow!10}
\pagecolor{pagebackground}
\begin{document}
\begin{tikzpicture}
  \coordinate (a) at (1,1);
  \draw [red](0,0) -- (a);
  \node [semicircle,draw,shape border rotate=180,anchor=chord center,outer sep=0cm,inner sep=0.2cm,fill=pagebackground] at (a) {};
\end{tikzpicture}
\end{document}

ここに画像の説明を入力してください

答え4

私は常にコードをできるだけシンプル (KISS) に保ち、理解して実際に保守できるようにしたいと考えています。そこで、@Qrrbrbirlbel のソリューションに基づいて、次のコードを使用します。

\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\usetikzlibrary{shapes.geometric}

\newcommand{\semicircleup}[4]{%
\node[circle,outer sep=0pt,inner sep=0,minimum width=2*#3] (#1) at #2 {};
\node[semicircle,shape border rotate=180,anchor=chord center,outer sep=0pt,inner sep=0,minimum width=2*#3,#4] at (#1) {};
}

\begin{tikzpicture}
\semicircleup{a}{(1,1)}{0.5cm}{draw,fill=white}
\draw (0,0) -- (a);
\end{tikzpicture}

\end{document}

名前付きの非表示の円ノード (線を切り取るため) と、同じ最小幅 ( inner sep=0) を持つ名前のない表示半円ノードを描画します。

追加の利点(私にとって重要)は、追加のライブラリが使用されないことです。

しかし、私は依然として @Qrrbrbirlbel の回答を彼のアイデアに対する称賛として受け入れます。

関連情報