切断 PSTricks 平行四边形的一部分,如果

切断 PSTricks 平行四边形的一部分,如果

首先:我也在LaTeX 社区几天前我就已经问过了,但我还没有得到任何答复。

考虑以下 MWE,它展示了来自太阳的光线穿过罗马万神殿的圆形天窗:

\documentclass{article}

\usepackage{auto-pst-pdf,pst-eucl,pstricks-add}
\usepackage[locale=DE]{siunitx}
\usepackage{expl3}

\ExplSyntaxOn
  \cs_new_eq:NN
    \calculate
  \fp_eval:n
\ExplSyntaxOff

\begin{document}

\def\radius{21.65 } % Radius of the dome
\def\vinkelA{12 }   % Width of the Oculus
\def\vinkelB{71 }   % Angle of the Sun's rays
\def\faktor{\calculate{1/3} }
\def\RelRadius{\calculate{\faktor*\radius} }
\def\vinkelC{\calculate{90-\vinkelA} }
\def\vinkelD{\calculate{90+\vinkelA} }
\def\vinkelE{\calculate{180+\vinkelC} }
\def\vinkelF{\calculate{180+\vinkelD} }
\def\vinkelG{\calculate{180-\vinkelB} }
\def\vinkelH{\calculate{180+\vinkelG} }
\begin{figure}
 \centering
  \begin{pspicture}(44,50)
  \psset{unit=0.5cm,linecolor=red}
   \pnode(0,0){A}
   \pnode(!0 \RelRadius){B}
   \pnode(!2 \RelRadius mul \RelRadius){C}
   \pnode(!2 \RelRadius mul 0){D}
   \pnode(!\RelRadius \RelRadius){E}
   \psarc(E){\RelRadius}{0}{\vinkelC}
   \psarc(E){\RelRadius}{\vinkelD}{180}
  \psset{linestyle=none,linecolor=black,dotsep=2pt}
   \psRelLine[angle=\vinkelF](E)(B){1}{P1}
   \psRelLine[angle=\vinkelE](E)(B){1}{P2}
   \psRelLine[angle=\vinkelG](P1)(P2){1}{L1}
   \psRelLine[angle=\vinkelH,linestyle=dotted](P2)(P1){1}{L2}
   \psRelLine[angle=\vinkelG](P2)(P1){1 \vinkelA cos add 2 \vinkelA sin mul \vinkelB sin mul div}{L3}
   \psParallelLine(L2)(L3)(L1){1}{L4}
   \pspolygon[fillstyle=solid,fillcolor=yellow](L1)(L2)(L3)(L4)
   \pnode(!0 1 \vinkelA cos add \RelRadius mul){T1}
   \pnode(!2 \RelRadius mul 1 \vinkelA cos add \RelRadius mul){T2}
   \pcline[linestyle=dotted](T1)(T2)
   \pstMarkAngle[linestyle=solid,MarkAngleRadius=0.8,LabelSep=1.5,arrows=<->]{L2}{P2}{T1}{\footnotesize{\SI{\vinkelB}{\degree}}}
   \psline[linestyle=solid,linecolor=red](C)(D)(A)(B)
  \end{pspicture}
\end{figure}

\end{document}

如果黄色平行四边形到达红色闭合曲线的左侧或右侧垂直部分,即光线照射到墙壁上,我想将其切断。我该怎么做?

PS 我完全没有使用 TikZ 的经验,所以如果要了解可能的答案,TikZ 不是最佳选择。话虽如此,我不会介意 TikZ 答案,但代码必须足够完整才能让我直接复制。

答案1

一种快速解决方案是将黄色平行四边形与红色矩形裁剪成大于约 45 度的 vinkelB 角。否则,您可以包含完整的圆顶路径进行裁剪,因为想法是相同的。

\documentclass{article}

\usepackage{pst-eucl,pstricks-add}
\usepackage[locale=DE]{siunitx}
\usepackage{expl3}

\ExplSyntaxOn
  \cs_new_eq:NN
    \calculate
  \fp_eval:n
\ExplSyntaxOff

\begin{document}

\def\radius{21.65 } % Radius of the dome
\def\vinkelA{12 }   % Width of the Oculus
\def\vinkelB{60 }   % Angle of the Sun's rays
\def\faktor{\calculate{1/3} }
\def\RelRadius{\calculate{\faktor*\radius} }
\def\vinkelC{\calculate{90-\vinkelA} }
\def\vinkelD{\calculate{90+\vinkelA} }
\def\vinkelE{\calculate{180+\vinkelC} }
\def\vinkelF{\calculate{180+\vinkelD} }
\def\vinkelG{\calculate{180-\vinkelB} }
\def\vinkelH{\calculate{180+\vinkelG} }

  \begin{pspicture}
  \psset{unit=0.5cm,linecolor=red}
   \pnode(0,0){A}
   \pnode(!0 \RelRadius){B}
   \pnode(!2 \RelRadius mul \RelRadius){C}
   \pnode(!2 \RelRadius mul 0){D}
   \pnode(!\RelRadius \RelRadius){E}
   \psarc(E){\RelRadius}{0}{\vinkelC}
   \psarc(E){\RelRadius}{\vinkelD}{180}
  \psset{linestyle=none,linecolor=black,dotsep=2pt}
   \psRelLine[angle=\vinkelF](E)(B){1}{P1}
   \psRelLine[angle=\vinkelE](E)(B){1}{P2}
   \psRelLine[angle=\vinkelG](P1)(P2){1}{L1}
   \psRelLine[angle=\vinkelH,linestyle=dotted](P2)(P1){1}{L2}
   \psRelLine[angle=\vinkelG](P2)(P1){1 \vinkelA cos add 2 \vinkelA sin mul \vinkelB sin mul div}{L3}
   \psParallelLine(L2)(L3)(L1){1}{L4}
   \begin{psclip}{\pspolygon(A)(D)(!2 \RelRadius mul \radius)(0,\radius)}
   \pspolygon[fillstyle=solid,fillcolor=yellow](L1)(L2)(L3)(L4)
   \end{psclip}
   \pnode(!0 1 \vinkelA cos add \RelRadius mul){T1}
   \pnode(!2 \RelRadius mul 1 \vinkelA cos add \RelRadius mul){T2}
   \pcline[linestyle=dotted](T1)(T2)
   \pstMarkAngle[linestyle=solid,MarkAngleRadius=0.8,LabelSep=1.5,arrows=<->]{L2}{P2}{T1}{\footnotesize{\SI{\vinkelB}{\degree}}}
   \psline[linestyle=solid,linecolor=red](C)(D)(A)(B)
  \end{pspicture}


\end{document}

在此处输入图片描述

这也是一个 Tikz 解决方案,如果您不想要阴影,只需删除preaction剪切路径内的选项。

\documentclass[tikz]{standalone}
\usetikzlibrary{calc}
\usepackage[locale=DE]{siunitx}


\begin{document}


\def\radius{8.66}    % Radius of the dome
\def\vinkelA{15.0}   % Width of the Oculus
\def\vinkelB{65}     % Angle of the Sun's rays
\pgfmathsetmacro\faktor{1/3}
\pgfmathsetmacro\RelRadius{\faktor*\radius}
\pgfmathsetmacro\oculus{2*\RelRadius/tan(90-\vinkelA)}
\begin{tikzpicture}
   \coordinate(A) at (0,0);
   \coordinate(B) at (0,\RelRadius cm);
   \coordinate(C) at (2*\RelRadius cm,\RelRadius cm);
   \coordinate(D) at (2*\RelRadius cm,0);
   \coordinate(E) at (\RelRadius cm,\RelRadius cm);
   \coordinate(F) at ($(E) + (90+\vinkelA:\RelRadius cm)$);
   \coordinate(G) at ($(E) + (90-\vinkelA:\RelRadius cm)$);

\begin{scope}
    \clip[preaction={top color=gray,bottom color=yellow!15}] % Shading
    (F) arc (90+\vinkelA:180:\RelRadius cm)|- (D) -- (C) arc (0:90-\vinkelA:\RelRadius cm);
    \draw[shorten <=-10 cm,yellow,line width=\oculus cm*0.9*sin(\vinkelB)] 
          ($(F)!0.5!(G)$) -- ++(-\vinkelB:30 cm);
\end{scope}

   \draw[red,ultra thick] (F) arc (90+\vinkelA:180:\RelRadius cm) 
              |- (D) -- (C) arc (0:90-\vinkelA:\RelRadius cm);

   \draw[shorten <=-2 cm,yellow,line width=\oculus cm*0.9*sin(\vinkelB)] 
          ($(F)!0.5!(G)$) --++(180-\vinkelB:2cm);

\draw[densely dotted] (A |-F) -- (D|-G) (G) -- ++(180-\vinkelB:2cm);
\draw[latex-latex] (G) ++(180-\vinkelB:10 mm) arc (180-\vinkelB:180:10 mm);
\node at ($(G)+(180-0.5*\vinkelB:1.3cm)$) {$\vinkelB^\circ$};
\end{tikzpicture}


\end{document}

在此处输入图片描述 在此处输入图片描述

答案2

没有必要使用 expl3 包...

\documentclass[pstricks]{standalone}
\usepackage{pst-eucl,pst-grad,pstricks-add}
\usepackage[locale=DE]{siunitx}

\begin{document}
\def\radius{21.65} % Radius of the dome
\def\faktor{0.3333}

\multido{\iA=10+5}{30}{%
\def\vinkelA{12 }   % Width of the Oculus
\def\vinkelB{\iA\space }   % Angle of the Sun's rays
\pstFPmul\RelRadius\faktor{\radius}
\psset{unit=0.5cm,linecolor=red}
\begin{pspicture}(-0.2,-0.2)(15,17)
   \pnode(0,0){A}
   \pnode(!0 \RelRadius){B}
   \pnode(!2 \RelRadius\space mul \RelRadius){C}
   \pnode(!2 \RelRadius\space mul 0){D}
   \pnode(!\RelRadius\space dup){E}
   \pscustom[linewidth=3pt,dimen=inner]{%
     \psline(A)(D)\psarc(E){\RelRadius}{0}{180}\psline(B)(A)}
   \psset{linestyle=none,linecolor=black,dotsep=2pt}
   \psRelLine[angle=!270 \vinkelA add ](E)(B){1}{P1}
   \psRelLine[angle=!270 \vinkelA sub](E)(B){1}{P2}
   \psRelLine[angle=!180 \vinkelB sub](P1)(P2){1}{L1}
   \psRelLine[angle=!360 \vinkelB sub,linestyle=dotted](P2)(P1){1}{L2}
   \psRelLine[angle=!180 \vinkelB sub](P2)(P1){1 \vinkelA cos add 2 \vinkelA sin mul \vinkelB sin mul div}{L3}
   \psParallelLine(L2)(L3)(L1){1}{L4}
   \begin{psclip}{\pscustom[linestyle=none,fillstyle=solid,fillcolor=blue!20]{%
     \psline(A)(D)(!\RelRadius\space dup add \RelRadius)
     \psarc(E){\RelRadius}{0}{180}\psline(B)(A)}}
     \pspolygon[fillstyle=solid,fillcolor=yellow](L1)(L2)(L3)(L4)
   \end{psclip}
   \pspolygon[fillstyle=solid,fillcolor=yellow](L1)(P1)(P2)(L2)
   \pnode(!0 1 \vinkelA cos add \RelRadius\space mul){T1}
   \pnode(!2 \RelRadius\space mul 1 \vinkelA cos add \RelRadius\space mul){T2}
   \pcline[linestyle=dotted](T1)(T2)
   \pstMarkAngle[linestyle=solid,MarkAngleRadius=0.8,LabelSep=1.5,arrows=<->]{L2}{P2}{T1}{\footnotesize{\SI{\vinkelB}{\degree}}}
\end{pspicture}}

\end{document}

在此处输入图片描述

还有一个更简单的解决方案,将坐标系的原点设置在中间,并使用黄色太阳光束的线宽:

\documentclass[pstricks]{standalone}
\usepackage{pstricks-add}
\usepackage[locale=DE]{siunitx}

\begin{document}
\def\radius{21.65} % Radius of the dome
\def\faktor{0.3333}
\def\vinkelA{12}   % Width of the Oculus
\makeatletter
\pst@getsinandcos{\vinkelA}
\pstFPmul\RelRadius\faktor{\radius}
\pstFPmul\MaxLW\RelRadius\pst@sin
\pstFPmul\MaxLW{2}{\MaxLW}

\multido{\iA=10+5}{16}{% % Angle of the Sun's rays
\psset{unit=0.5cm}
\begin{pspicture}(-\RelRadius,-\RelRadius)(\RelRadius,10)
  \pst@getsinandcos{\iA}
  \pstFPmul\RelLW{\MaxLW}{\pst@sin}
  \pnode(-\RelRadius,-\RelRadius){A}
  \pnode(-\RelRadius,0){B}
  \pnode(0,0){C}
  \pnode(\RelRadius,-\RelRadius){D}
  \pnode(!0 \RelRadius\space \vinkelA\space cos mul){T1}
  \rput(!0 \RelRadius\space \vinkelA\space cos mul){%
        \pcline[linecolor=yellow,linewidth=\RelLW,nodesepB=-8,nodesepA=-1]%
       (0,0)(!-1 \iA\space neg Tan neg)}
  \begin{psclip}{%
    \pscustom[linewidth=2pt,linecolor=red,fillstyle=solid,fillcolor=blue!20]{%
    \psarc(C){\RelRadius}{!90 \vinkelA\space add}{180}
    \psline(B)(A)(D)
    \psarc(C){\RelRadius}{0}{!90 \vinkelA\space sub}}}
    \rput(!0 \RelRadius\space \vinkelA\space cos mul){%
        \pcline[linecolor=yellow,linewidth=\RelLW,nodesep=-4]%
       (0,0)(!\RelRadius\space dup \iA\space neg Tan mul )}
  \end{psclip}
  \psline[linestyle=dotted]({-\RelRadius,0}|T1)({\RelRadius,0}|T1)
  \rput(!\RelRadius\space 90 \vinkelA\space sub PtoC){%
    \pswedge(0,0){1}{!180 \iA\space sub}{180}
    \uput{1}[!180 \iA\space 2 div sub](0,0){\footnotesize\SI{\iA}{\degree}}
    \psline[linestyle=dotted](0,0)(!3 180 \iA\space sub PtoC)
  }
\end{pspicture}}

\end{document}

在此处输入图片描述

相关内容