Loading [MathJax]/jax/output/CommonHTML/jax.js

2021年3月12日金曜日

TikZの円弧

 TikZの円弧の描画方法が微妙だったので,まとめておく。

昨日のレンズの作図で苦労したのであった。\draw circle で,中心と半径を指定した状態ではは開始角度と終了角度の指定ができない。\draw arcを使うことになるが,このときは,中心座標(x0, y0)ではなく,開始点座標 (xi, yi)をいれることになる。中心座標はこれから,次式で計算される位置になる。一般的な楕円に拡張して半径を(a, b)とすると,

x0=xiacosθiy0=yibsinθi

これが簡単な場合もあるだろうが,始点や終点や中心を決めたい場合は面倒ではないのか。

\ begin{tikzpicture}
\tikzstyle{every node}=[font = \large];
\draw (0,0) node[below left]{O};
\draw[->] (-4,0) -- (4,0) node[right]{x};
\draw[->] (0,-4) -- (0,4) node[above]{y};
\draw[step=1.0, dotted] (-4,-4) grid (4,4);
\draw (0,1) circle(1);
\draw (1,2) circle(1 and 2);
\draw (2,3) ellipse(2 and 1);
\filldraw[orange!50!white,semitransparent] (-2,-1) arc (135:-30:2);
\filldraw[cyan!50!white,semitransparent] (-2,-1) arc (135:210:2);
\filldraw[gray] (-0.59,-2.41) circle(1pt);
\filldraw (-2,-1) circle(1pt);
\draw[red, thick] (-3,-2) arc (135:-30:2 and 1);
\draw[blue, thick] (-3,-2) arc (135:210:2 and 1);
\filldraw[gray] (-1.59,-2.71) circle(1pt);
\filldraw (-3,-2) circle(1pt);
\node at (-2.5,3.5) {x0=xiacosθi};
\node at (-2.5,2.5) {y0=yibsinθi};
\ end{tikzpicture}


図 TikZでの円弧の描画方法


0 件のコメント: