
編集:私は、この特定の図形をどのように描画するかではなく、pgf デコレーションを使用してこの問題をどのように解決できるか、またはできないかに興味があります。
私は、次のように、点が四角形の点線を描画するために、pgf の線の装飾を使用しようとしています。
ただし、pgf は次のコードのように、正方形が描画される環境を自動的に回転します。
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc,decorations}
\pgfdeclaredecoration{Squares}{initial}{
\state{initial}[width=10pt]{
\fill (0cm,0cm) rectangle (5pt,5pt);
}
\state{final}{
\pgfpathlineto{\pgfpointdecoratedpathlast}
}
}
\begin{document}
\begin{center}
\begin{tikzpicture}
\draw[decorate,decoration=Squares] (0,0) -- (5,5);
\end{tikzpicture}
\end{center}
\end{document}
出力は次のようになります:
自動回転を補正したり、無効にしたりする方法はありますか?
答え1
\fill
デコレーション コード ( で指定) を入力したときの回転と反対方向にデコレーション コマンドを回転させます\pgfdecoratedangle
。
\documentclass[tikz]{standalone}
\usetikzlibrary{calc,decorations}
\pgfdeclaredecoration{Squares}{initial}{
\state{initial}[width=10pt]{
\fill[rotate=-\pgfdecoratedangle] (0cm,0cm) rectangle (5pt,5pt);
}
\state{final}{
\pgfpathlineto{\pgfpointdecoratedpathlast}
}
}
\begin{document}
\begin{tikzpicture}
\draw[decorate,decoration=Squares] (0,0) -- (1,5);
\draw[decorate,decoration=Squares] (0,0) -- (5,5);
\draw[decorate,decoration=Squares] (0,0) to[out=0,in=-90] (5,5);
\draw[decorate,decoration=Squares] (0,0) -- (5,1);
\end{tikzpicture}
\end{document}