pstricks 座標から postscript 座標への変換

pstricks 座標から postscript 座標への変換

私は pstricks 上にカスタム グラフィック ライブラリを作成しており、pstricks 座標から postscript 座標に変換する必要があります。私は、試行錯誤の末に作り上げた「実用的な」例を持っていますが、これは適切に実行できると確信しています。pstricks.tex ファイルを読んで、pstricks は \pst@coor または他のマクロ (おそらく、もっとよくご存知でしょう) を使用して、pstricks 座標から postscript 座標に変換しているという印象を受けました。それがどのように機能するかは、まだ解読できていません。そこで、私の実用的なソリューションをここに示します。

具体的な質問は、以下のコードで \fcConvertPSXUnit と \fcConvertPSYUnit の代わりに使用する必要があるネイティブの pstricks 変換関数は何ですか? [編集] 以下の質問はHerbertによって回答されました。この投稿に彼の回答を含めます。

適切に実行されれば、以下のコードは完全な正方形の十字を表示します (十字の上部はネイティブの pstricks を使用して描画され、下部は変換関数を使用して描画されます)。

\documentclass{article}
\usepackage{auto-pst-pdf} 
%to convert points to numbers, macro copied from stackexchange
\makeatletter
\begingroup
\catcode `P=12  % digits and punct. catcode
\catcode `T=12  % digits and punct. catcode
\lowercase{%
\def\x{\def\rem@pt##1.##2PT{##1\ifnum##2>\z@.##2\fi}}}
\expandafter\endgroup\x%
\newcommand{\stripPoints}[1]{\expandafter\rem@pt\the#1}
\newcommand{\fcConvertPSXUnit}{\stripPoints{\psxunit} 72.27 div 8000 mul mul\space %
\pst@number\pst@dima\space %3 sub 
72.27 div 8000 mul sub  %
}%
\newcommand{\fcConvertPSYUnit}{\stripPoints{\psyunit} 72.27 div -8000 mul mul\space %
\pst@number\pst@dimb\space 72.27 div -8000 mul sub %
}%
\makeatother

\begin{document}
\psset{xunit=1.2cm, yunit=1.2cm}
\begin{pspicture}(-2.3,-2.7)(2.1,2.55)%
\psline (0,0)(0,1)%
\psline (0,0)(1,0)%
\pstVerb{ %
100 setlinewidth %
newpath %
0 \fcConvertPSXUnit 0 \fcConvertPSYUnit moveto %
-1 \fcConvertPSXUnit 0 \fcConvertPSYUnit lineto %
0 \fcConvertPSXUnit 0 \fcConvertPSYUnit moveto %
0 \fcConvertPSXUnit -1 \fcConvertPSYUnit lineto %
stroke %
}%
\end{pspicture}
\end{document}

アドバイスありがとうございます!

上記のファイルをコンパイルした結果

私の質問に答えるハーバートからのコード:

\documentclass{article}
\usepackage{auto-pst-pdf}
\usepackage{pstricks} %that should had been included

\begin{document}

\psset{xunit=1.2cm, yunit=1.2cm}
\begin{pspicture}(-2.3,-2.7)(2.1,2.55)%
\makeatletter
\psline (0,0)(0,1)%
\psline (0,0)(1,0)%
\pscustom{ %
\code{ %
100 setlinewidth %
newpath %
0  0 \tx@ScreenCoor\space moveto %
-1 0 \tx@ScreenCoor\space lineto %
0 0 \tx@ScreenCoor\space moveto %
0 -1 \tx@ScreenCoor\space lineto %
stroke %
}%
}%
\makeatother

\end{pspicture}
\end{document}

答え1

\documentclass{article}
\usepackage{pstricks} 

\begin{document}
\psset{xunit=1.2cm, yunit=1.2cm}
\begin{pspicture}[showgrid](-2.3,-2.7)(2.1,2.55)
\psline (0,0)(0,1)
\psline (0,0)(1,0)
\pscustom{
  \moveto(0,0) 
  \lineto(-1,0) 
  \moveto(0,0) 
  \lineto(0,-1) 
  \stroke[linewidth=2pt,linecolor=red] 
}
\end{pspicture}
\end{document}

\moveto基本的なマクロなどが必要ない場合は、たとえば次のようにします。

\code{0 0 moveto -1 0 \tx@ScreenCoor\space lineto}

環境の内側\pscustom\makeatletter前に が付きますpspicture:

\documentclass{article}
\usepackage{auto-pst-pdf}
\usepackage{pstricks}
\begin{document}

\makeatletter
\psset{xunit=1.2cm, yunit=1.2cm}
\begin{pspicture}(-2.3,-2.7)(2.1,2.55)
\psline (0,0)(0,1)
\psline (0,0)(1,0)
\pscustom{% 
\code{
newpath 
2 setlinewidth 
0  0 \tx@ScreenCoor\space moveto 
-1 0 \tx@ScreenCoor\space lineto 
0 0 \tx@ScreenCoor\space moveto 
0 -1 \tx@ScreenCoor\space lineto 
stroke 
}}%
\end{pspicture}
\makeatother
\end{document}

関連情報