我亲爱的PSTRICKS朋友们,
有时我喜欢有一个\psline
显示其长度的东西,比如说\psmline
。
在我的带箭头的线条最小工作示例中,\marrow
我误用了 \multirput 来生成空白。有人知道如何正确定义它吗?
亲切的问候
汉斯·尤尔根
\FPset\hjsxi{#1}
\FPset\hjsxii{#3}
\FPset\hjsyi{#2}
\FPset\hjsyii{#4}
\FPifeq\hjsxi\hjsxii\FPset\hjsgrad{90}\FPset\hjssin{1}\FPset\hjscos{0}\else\FPsub\hjssin\hjsyi\hjsyii\FPsub\hjscos\hjsxi\hjsxii\FPdiv\hjstan\hjssin\hjscos\FParctan\hjsarctan\hjstan\FPdiv\hjsgrad\hjsarctan\FPpi\FPmul\hjsgrad\hjsgrad{180}
\fi
\FPmul\hjsdx\hjscos{0.001}
\FPmul\hjsdy\hjssin{0.001}
\FPadd\hjsx\hjsxi\hjsxii%
\FPadd\hjsy\hjsyi\hjsyii
\FPdiv\hjsx\hjsx{2}
\FPdiv\hjsy\hjsy{2}
\FPsub\hjsxa\hjsxii\hjsxi
\FPmul\hjsxa\hjsxa\hjsxa
\FPsub\hjsya\hjsyii\hjsyi
\FPmul\hjsya\hjsya\hjsya
\FPadd\hjsz\hjsxa\hjsya
\FPeval\hjsz{root(2,\hjsz)}
\FPeval\hjsz{round(\hjsz,2)}
\FPeval\hjsx{clip(\hjsx)}
\FPeval\hjsy{clip(\hjsy)}
\FPeval\hjsz{clip(\hjsz)}
\FPeval\hjsrgrad{round(\hjsgrad,1)}
\FPeval\hjsrgrad{clip(\hjsrgrad)}
\multirput{\hjsrgrad}(\hjsx,\hjsy)(\hjsdx,\hjsdy){18}{\white $\hjsz$}
\multirput{\hjsrgrad}(\hjsx,\hjsy)(-\hjsdx,-\hjsdy){18}{\white $\hjsz$}
\rput{\hjsrgrad}(\hjsx,\hjsy){$\hjsz$}
} %end marrows
\def\hjsput[#1](#2,#3){\uput[#1](#2,#3){$(#2,#3)$}\rput(#2,#3){$\times$}
} %end hjsput
\documentclass{article}
\usepackage{pstricks}
\usepackage{fp}
\begin{document}
\begin{pspicture}(-5,-5)(5,5)
\hjsput[ur](4,4)
\hjsput[dr](4,-4)
\hjsput[dl](-4,-4)
\hjsput[ul](-4,4)
\marrows(0,0)(0,4)
\marrows(0,0)(4,0)
\marrows(0,0)(0,-4)
\marrows(0,0)(-4,0)
\marrows(0,0)(4,4)
\marrows(0,0)(-4,4)
% north
\marrows(0,0)(3,4)
\marrows(0,0)(4,3)
\marrows(0,0)(-4,3)
\marrows(0,0)(-3,4)
\marrows(0,0)(2,4)
\marrows(0,0)(4,2)
\marrows(0,0)(-4,2)
\marrows(0,0)(-2,4)
\marrows(0,0)(1,4)
\marrows(0,0)(4,1)
\marrows(0,0)(-4,1)
\marrows(0,0)(-1,4)
% south
\marrows(0,0)(3,-4)
\marrows(0,0)(4,-3)
\marrows(0,0)(-4,-3)
\marrows(0,0)(-3,-4)
\end{pspicture}
\end{document}
答案1
具体到您展示的示例,您可以使用\fpeval
(从xfp
nodesepA
)。然后,通过调整/长度,在线的中间放置一个节点,并留出长度和微小的间隙nodesepB
:
\documentclass{article}
\usepackage{pst-plot,pst-node}
\begin{document}
\begin{pspicture}(-5,-5)(5,5)
%\psaxes{<->}(0,0)(-4,-4)(4,4)
\pnode(0,0){origin}% Define origin node
\multido{\rA=0+\fpeval{360/32}}{32}{%
\edef\radiusX{\fpeval{((\rA > 45) && (\rA < 135)) || ((\rA > 225) && (\rA < 315)) ? 4 / tan(\rA * pi / 180) : ((\rA > 90) && (\rA < 270) ? -4 : 4)}}% x-length
\edef\radiusY{\fpeval{((\rA > 45) && (\rA < 135)) || ((\rA > 225) && (\rA < 315)) ? ((\rA > 0) && (\rA < 180) ? 4 : -4) : 4 * tan(\rA * pi / 180)}}% y-length
\pnode(\radiusX,\radiusY){e\rA}% Define end node
\ncline[linestyle=none]{-}{origin}{e\rA}%
\ncput[npos=0.5]{\Rnode{m\rA}{\small\fpeval{round(sqrt((\radiusX)^2+(\radiusY)^2),1)}}}% Define middle node
\ncline[nodesepB=2pt]{-}{origin}{m\rA}% Origin -> middle
\ncline[nodesepA=2pt]{->}{m\rA}{e\rA}% middle -> end
}
\end{pspicture}
\end{document}
对于更一般的内容,也许以下内容是一个足够的起点:
\documentclass{article}
\usepackage{pst-plot,pst-node}
\newcommand{\linewithlength}[3][]{{%
\psset{#1}% Local settings
\pnode(#2){start}% Set start node
\pnode(#3){end}% Set end node
\psGetDistance(#2)(#3)\DistanceVal% Calculate distance
\ncline[linestyle=none]{-}{start}{end}\ncput[npos=0.5]{\Rnode{mid}{\fpeval{trunc(\DistanceVal,1)}}}% Set distance/length
\ncline[nodesepB=2pt]{-}{start}{mid}\ncline[nodesepA=2pt]{->}{mid}{end}% Line segments
}}
\begin{document}
\begin{pspicture}(10,10)
\linewithlength{1,2}{3,4}
\linewithlength{1,4}{5,3.14152}
\linewithlength{0,0}{-1,5}
\end{pspicture}
\end{document}
答案2
这是您的启动器。使用lualatex
!!运行它
\documentclass[pstricks]{standalone}
\usepackage{pst-plot,pst-node}
\def\myLineY#1{%
\pcline{->}(0,0)(!4 dup #1 tan mul)
\ncput*{\directlua{
tex.print(math.floor(4/math.cos(#1*math.pi/180)*10)/10)}}
\pcline{->}(0,0)(!-4 4 #1 tan mul)}
\def\myLineX#1{%
\pcline{->}(0,0)(!4 #1 tan div 4)
\pcline{->}(0,0)(!-4 #1 tan div -4)}
\begin{document}
\begin{pspicture}(-5,-5)(5,5)
\psaxes{<->}(0,0)(-4,-4)(4,4)
\multido{\iA=-45+15}{7}{\myLineY{\iA}}
\multido{\iA=45+15}{6}{\myLineX{\iA}}
\end{pspicture}
\end{document}
\end{document}