围绕点旋转多边形

围绕点旋转多边形

我有以下代码:

\documentclass[a4paper]{article}
\usepackage{pstricks}
\usepackage{pst-plot}
\begin{document}
\begin{pspicture}(-6,-10)(10,10)
\psset{xunit=1cm,yunit=1cm,linewidth=0.5\pslinewidth}
\psgrid[gridcolor=lightgray,subgridcolor=lightgray,subgriddiv=2, gridlabels=0](-10,-10)(10,10)(-10,-10)
\psaxes[xsubticks=2,xsubticksize=0.5,showorigin=false,ticks=all]{->}(0,0)(-10,0)(10,0)
\psaxes[ysubticks=2,ysubticksize=0.5,showorigin=false]{->}(0,0)(0,-10)(0,10)
\psset{linewidth=3\pslinewidth}
\psdots(3,4)\uput{0.2}[0](3,4){$P(3|4)$}
\pspolygon
(6,-4)
(7,-4)
(7,-3)
(8,-3)
(8,-4)
(9,-4)
(9,-2)
(8,-2)
(8,1)
(9,1)
(9,3)
(8,3)
(8,2)
(7,2)
(7,3)
(6,3)
(6,1)
(7,1)
(7,-2)
(6,-2)
(6,-4)
\end{pspicture}
\end{document}

使用时\rput,多边形似乎围绕 O(0/0) 旋转,但我希望它围绕 P(3/4) 旋转。使用平移功能\rput[tl]{-120}(3,4){...}也不起作用。我确信,我忽略了一些非常明显的东西,但我不明白……

有人可以帮忙吗?

答案1

您可以使用嵌套的 `\rput 来相对于另一个坐标点旋转某个对象。例如,使用“伪代码”:

\rput{<angle>}(<point>){
  \rput(-<point>){
    <stuff>
  }
}

在此处输入图片描述

\documentclass[a4paper]{article}
\usepackage{pstricks}
\usepackage{pst-plot}
\begin{document}

\begin{pspicture}(-6,-10)(10,10)
  \psset{xunit=1cm,yunit=1cm,linewidth=0.5\pslinewidth,fillstyle=solid}
  \psgrid[gridcolor=lightgray,subgridcolor=lightgray,subgriddiv=2, gridlabels=0](-10,-10)(10,10)(-10,-10)
  \psaxes[xsubticks=2,xsubticksize=0.5,showorigin=false,ticks=all]{->}(0,0)(-10,0)(10,0)
  \psaxes[ysubticks=2,ysubticksize=0.5,showorigin=false]{->}(0,0)(0,-10)(0,10)
  \psset{linewidth=3\pslinewidth}
  \psdots(3,4)\uput{0.2}[0](3,4){$P(3|4)$}
  \pspolygon[fillcolor=red]
    (6,-4)(7,-4)(7,-3)(8,-3)(8,-4)(9,-4)(9,-2)(8,-2)(8,1)
    (9,1)(9,3)(8,3)(8,2)(7,2)(7,3)(6,3)(6,1)(7,1)(7,-2)
    (6,-2)(6,-4)
  \rput{-90}{\pspolygon[fillcolor=green]% Rotated about origin (0,0)
    (6,-4)(7,-4)(7,-3)(8,-3)(8,-4)(9,-4)(9,-2)(8,-2)(8,1)
    (9,1)(9,3)(8,3)(8,2)(7,2)(7,3)(6,3)(6,1)(7,1)(7,-2)
    (6,-2)(6,-4)}
  \rput{-90}(3,4){\pspolygon[fillcolor=blue]% Rotated about P (3,4), with all coordinates relative to P
    (6,-4)(7,-4)(7,-3)(8,-3)(8,-4)(9,-4)(9,-2)(8,-2)(8,1)
    (9,1)(9,3)(8,3)(8,2)(7,2)(7,3)(6,3)(6,1)(7,1)(7,-2)
    (6,-2)(6,-4)}
  \rput{-90}(3,4){\rput(-3,-4){\pspolygon[fillcolor=yellow]% Rotated about P (3,4)
    (6,-4)(7,-4)(7,-3)(8,-3)(8,-4)(9,-4)(9,-2)(8,-2)(8,1)
    (9,1)(9,3)(8,3)(8,2)(7,2)(7,3)(6,3)(6,1)(7,1)(7,-2)
    (6,-2)(6,-4)}}
\end{pspicture}

\end{document}

相关内容