考虑以下示例。
代码
% pdflatex -shell-escape test.tex
\documentclass{article}
\usepackage{
auto-pst-pdf,
pst-eucl,
pstricks-add
}
\usepackage[
locale=DE
]{siunitx}
\begin{document}
\begin{figure}
\def\radius{21.65 } % radius
\def\vinkelA{12 } % angle
\def\faktor{0.33333333 } % scaling
\newlength\maksimum % define length
\maksimum=\radius\psunit % set the length to the current value/unit
\maksimum=2\dimexpr\faktor\maksimum
\centering
\psset{
unit=0.8cm,
linecolor=red
}
\begin{pspicture}(\maksimum,\maksimum)
\pnode(!2 \faktor \radius mul mul \faktor \radius mul){A}
\pnode(!\faktor \radius mul \faktor \radius mul){B}
\pnode(!\faktor \radius mul 1 \vinkelA cos add \faktor \radius mul mul){C}
\psline(A)(!2 \faktor \radius mul mul 0)(0,0)(!0 \faktor \radius mul)
\psarc(B){!\faktor \radius mul}{0}{!90 \vinkelA sub}
\psarc(B){!\faktor \radius mul}{!90 \vinkelA add}{180}
\psline[linestyle=dashed](!0 \faktor \radius mul)(A)
\psarc[linestyle=dashed](B){!\faktor \radius mul}{180}{360}
\psset{
linecolor=blue,
linewidth=1.5pt
}
\psRelLine[angle=!270 \vinkelA add](B)(!0 \faktor \radius mul){1}{P1}
\psRelLine[angle=!90 \vinkelA sub](B)(A){1}{P2}
\pcline(B)(P1)
\pcline(B)(P2)
\pcline[linestyle=none](P1)(P2)
\aput*{:U}{Oculus}
\pcline(P1)(P2)
\pcline(B)(C)
\psset{
linecolor=black,
linewidth=0.5pt,
MarkAngleRadius=3.7,
LabelSep=4
}
\psRelLine[linestyle=dotted,angle=45]{<->}(B)(A){1}{V}
\ncline[linestyle=none]{B}{V}
\naput[nrot=:U]{\small\SI{\radius}{\m}}
\pstMarkAngle{C}{B}{P1}{\scriptsize\SI{\vinkelA}{\degree}}
\pstMarkAngle{P2}{B}{C}{\scriptsize\SI{\vinkelA}{\degree}}
\pstRightAngle{P1}{C}{B}
\pstRightAngle{P2}{C}{B}
\end{pspicture}
\end{figure}
\end{document}
输出
问题
我想改进代码。我已经在开始的基础上对其进行了一些改进,但我显然可以做得更好。
答案1
\documentclass{article}
\usepackage{auto-pst-pdf,pst-node}
\begin{document}
\psset{unit=3mm}
\def\radius{21.65 } % radius
\def\vinkelA{12 } % angle
\begin{pspicture}(-\radius,-\radius)(\radius,\radius)
\psarc[linestyle=dashed,linecolor=red](0,0){\radius}{180}{360}
\psarc[linecolor=red](0,0){\radius}{0}{!90 \vinkelA sub}
\psarc[linecolor=red](0,0){\radius}{!90 \vinkelA add}{180}
\psline[linecolor=red](-\radius,0)(-\radius,-\radius)(\radius,-\radius)(\radius,0)
\psline[linecolor=red,linestyle=dashed](-\radius,0)(\radius,0)
\psarc(0,0){!\radius 2 div}{!90 \vinkelA sub}{!90 \vinkelA add}
\uput[90](!\radius 2 div 90 \vinkelA 2 div sub PtoC){$\vinkelA^\circ$}
\uput[90](!\radius 2 div 90 \vinkelA 2 div add PtoC){$\vinkelA^\circ$}
\pnode(!0 \radius \vinkelA cos mul){Oculus}
\pspolygon[linecolor=blue,linewidth=1.5pt,linejoin=1]%
(!\radius 90 \vinkelA add PtoC)(0,0)(!\radius 90 \vinkelA sub PtoC)
\psline[linecolor=blue,linewidth=1.5pt](Oculus)
\psline[linestyle=dotted]{<->}(\radius;45)
\uput[90]{45}(!\radius 2 div 45 PtoC){\radius}
\uput[90](0,\radius){Oculus}
\rput[t](Oculus){\psline(-1.5,0)(-1.5,-1.5)(1.5,-1.5)(1.5,0)}
\end{pspicture}
\end{document}