什么原因导致我的切线和法线在视觉上不垂直?

什么原因导致我的切线和法线在视觉上不垂直?
\documentclass[pstricks,border=12pt,dvipsnames]{standalone}

\usepackage{pstricks-add}
\usepackage[nomessages]{fp}

\FPset\LabelBase{4}
\FPeval\DeltaX{pi/LabelBase}
\FPset\DeltaY{1}

\FPeval\Left{0 -pi/4 -DeltaX/2}
\FPeval\Right{2*pi +DeltaX/2}
\FPeval\Bottom{0 -3 -DeltaY/2}
\FPeval\Top{3 +DeltaY/2}

\newlength\Width\Width=8cm
\newlength\Height\Height=6cm
\newlength\urx\urx=15pt
\newlength\ury\ury=15pt
\newlength\llx\llx=-15pt
\newlength\lly\lly=-15pt

\psset
{
    trigLabels,
    trigLabelBase=\LabelBase,
    urx=\urx,
    ury=\ury,
    llx=\llx,
    lly=\lly,
    algebraic,
    plotpoints=1000,
    xAxisLabel=$x$,
    yAxisLabel=$y$, 
}

\def\f{sin(x)+sin(2*x)+sin(3*x)}
%\def\fp{cos(x)+2*cos(2*x)+3*cos(3*x)}

\def\fp{Derive(1,\f)}

\begin{document}
\begin{psgraph}[dx=\DeltaX,dy=\DeltaY]{->}(0,0)(\Left,\Bottom)(\Right,\Top){\dimexpr\Width-\urx+\llx}{\dimexpr\Height-\ury+\lly}
    \psplot[linecolor=NavyBlue]{Pi -4 div}{TwoPi}{\f}
    \pstVerb{/xxx {Pi 4 div}def}
    \psCoordinates[linestyle=dashed,linecolor=gray](*xxx {\f})
    \psplotTangent[linecolor=Red,Derive={\fp}]{xxx}{1}{\f}
    \psplotTangent[linecolor=Green,Derive={-1/\fp}]{xxx}{1}{\f}
\end{psgraph}
\end{document}

在此处输入图片描述

什么原因导致我的切线和法线不垂直?

答案1

输出绝对正确!从数学角度来看,这两条线是垂直的:

\documentclass[pstricks,border=12pt,dvipsnames]{standalone}

\begin{document}
\psset{yunit=2}
\begin{pspicture}[showgrid](3,3)
\psline(3,3)\psline(0,3)(3,0)
\psset{unit=1cm,linecolor=red}
\psline(3,3)\psline(0,3)(3,0)
\end{pspicture}

\end{document}

在此处输入图片描述

在您的示例中,您有不同的 x 和 y 单位。如果您不想要变量缩放,则不要使用\psgraph。它专为固定的通过变量缩放来调整图像的宽度和高度!

\begin{pspicture}(-1,-3.5)(7,4)
\psaxes[trigLabelBase=4,dx=0.75\pstRadUnit]{->}(0,0)(\Left,\Bottom)(\Right,\Top)[$x$,90][$y$,0]
\pstVerb{/xxx {Pi 4 div} def}%
\psplot[linecolor=NavyBlue]{xxx neg}{TwoPi}{\f}
\psCoordinates[linestyle=dashed,linecolor=gray](*xxx {\f})%
\psplotTangent[linecolor=Red,Derive={\fp}]{xxx}{1}{\f}%
\psplotTangent[linecolor=Green,Derive={-1/(\fp)}]{xxx}{1}{\f}
\end{pspicture}
\end{document}

在此处输入图片描述

但是,psgraph允许按比例缩放!

\begin{psgraph}[options](x,y)(x,y){Width}{!}

它类似于\resizebox

答案2

另一个只是为了好玩的解决方案!它是如何工作的?我让高度成为宽度的函数,这样水平和垂直都使用相同的公制比例。

\documentclass[pstricks,border=0pt,dvipsnames]{standalone}

\usepackage{pstricks-add}
\usepackage[nomessages]{fp}

\FPset\LabelBase{4}
\FPeval\DeltaX{pi/LabelBase}
\FPset\DeltaY{1}

\FPeval\Left{0 -pi/4 -DeltaX/2}
\FPeval\Right{2*pi +DeltaX/2}
\FPeval\Bottom{0 -3 -DeltaY/2}
\FPeval\Top{3 +DeltaY/2}

\FPeval\NormedXUnit{1/(Right-Left)}
\FPeval\NormedYUnit{1/(Top-Bottom)}
\FPeval\factor{NormedXUnit/NormedYUnit}

\newlength\urx\urx=15pt
\newlength\ury\ury=15pt
\newlength\llx\llx=-15pt
\newlength\lly\lly=-15pt

\newlength\Width\Width=8cm
\newlength\Height\Height=\dimexpr\factor\dimexpr\Width-\urx+\llx\relax+\ury-\lly\relax

\psset
{
    trigLabels,
    trigLabelBase=\LabelBase,
    urx=\urx,
    ury=\ury,
    llx=\llx,
    lly=\lly,
    algebraic,
    plotpoints=1000,
    xAxisLabel=$x$,
    yAxisLabel=$y$, 
}

\def\f{sin(x)+sin(2*x)+sin(3*x)}
%\def\fp{cos(x)+2*cos(2*x)+3*cos(3*x)}

\def\fp{Derive(1,\f)}

\begin{document}
\begin{psgraph}[dx=\DeltaX,dy=\DeltaY]{->}(0,0)(\Left,\Bottom)(\Right,\Top){\dimexpr\Width-\urx+\llx}{\dimexpr\Height-\ury+\lly}
    \psplot[linecolor=NavyBlue]{Pi -4 div}{TwoPi}{\f}
    \pstVerb{/xxx {Pi 4 div} def}
    \psCoordinates[linestyle=dashed,linecolor=gray](*xxx {\f})
    \psplotTangent[linecolor=Red,Derive={\fp}]{xxx}{1}{\f}
    \psplotTangent[linecolor=Green,Derive={-1/\fp}]{xxx}{1}{\f}
\end{psgraph}
\end{document}

在此处输入图片描述

相关内容