從 pstricks 座標到 postscript 座標的轉換

從 pstricks 座標到 postscript 座標的轉換

我正在 pstricks 之上製作一個自訂圖形庫,我需要從 pstricks 座標轉換為 postscript 座標。我有一個「工作」範例,是透過痛苦的試誤過程編寫的,但我確信它可以正確完成。閱讀 pstricks.tex 文件,我留下的印像是 pstricks 使用某種 \pst@coor 或 - 一些其他巨集 - 也許你更了解 - 從 pstricks 座標轉換為 postscript 座標。我無法解碼它是如何工作的。這是我的工作解決方案。

我向您提出的具體問題是:我應該使用什麼本機 pstricks 轉換函數來代替下面程式碼中的 \fcConvertPSXUnit 和 \fcConvertPSYUnit ? [編輯]赫伯特在下面回答了問題。包括他在這篇文章中的回答。

如果做得正確,下面的程式碼應該顯示一個完美的方形十字(十字的頂部部分是使用本機 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}

相關內容