私は古い pstricks コードをいくつか持っており、それを TikZ でやり直しています。現在の図では、x スケールと y スケールが異なります。
\begin{tikzpicture}[xscale=1.8,yscale=4]
しかし、この方法では円が楕円として描かれ、y方向に引き伸ばされてしまうという問題があります。私はまた、
\begin{tikzpicture}[x=1.8cm,y=4cm]
しかし、これは円を楕円に引き伸ばすのと同じ効果があります。
では、オブジェクトの形状に影響を与えずに、TikZ でのみ座標をスケーリングする方法はありますか?
答え1
私は次のような解決策を発見しました
\draw (1,1) circle(0.1cm);
役に立ちます。私は
\draw (1,1) circle(0.1);
個々のスケーリングを取得します。
答え2
PSTricks は\psrunit
描画時に使用します\pscircle
。
\documentclass[tikz,border=12pt]{standalone}
\newlength\runit
\runit=1cm
\edef\Radius#1{#1\runit}
\begin{document}
\begin{tikzpicture}[x=3cm,y=2cm]
\draw[fill=red] (0,0) circle (\Radius{2});
\draw (-2,-2) rectangle (2,2);
\end{tikzpicture}
\end{document}
注: ラジアル単位をグローバルに宣言すると、円の半径のすべての単位を 1 か所で変更できるという利点があります。
このラジアル ユニットに簡単にアクセスできるように、新しいキーを宣言することもできます。
\documentclass[tikz,border=12pt]{standalone}
\makeatletter
\newlength\tikz@runit
\tikzset{
r/.code=\pgfmathsetlength\tikz@runit{#1},
r=+1cm, % setting a default value
r radius/.style={radius={(#1)*\tikz@runit}},
xr radius/.style={x radius={(#1)*\tikz@runit}},
yr radius/.style={y radius={(#1)*\tikz@runit}}
}
\makeatother
\begin{document}
\begin{tikzpicture}[x=3cm,y=2cm]
\fill[fill=red] (0,0) circle [r radius=1+1];
\fill[fill=green] (-1,1) circle [xr radius=1+3/4, yr radius=1-1/3]
(1,1) circle [xr radius=1+3/4, yr radius=1-1/3];
\draw (-2,-2) rectangle (2,2);
\end{tikzpicture}
\end{document}
答え3
提案されたすべてのソリューションの重要なアイデアは、単位をx=
と に変更することに依存していますy=
。これはうまく機能します。
しかし、私のコードでは、xscale=
とを使用することが非常に望ましいですyscale=
。そのため、非常に単純なマクロを設定しました。
\newcommand{\pnt}[3][black]{%
\begin{scope}[shift={#2}];
\fill[color=#1,shift only] (0,0) circle(#3);
\end{scope}}
これは以下と一緒に使用されます:
\pnt[red]{(3,4)}{0.06}
を配置する円形位置(3,4)にある半径1.5ptの赤い点。