根据命名坐标旋转三角形

根据命名坐标旋转三角形

我正在准备一个关于微型计算机断层扫描的演示文稿,我已经有一段时间没有使用 TikZ 了。

我不知道如何才能让下图中的灰色射线锥体围绕图形中心旋转。

\documentclass[export]{standalone}
\usepackage{animate}
\usepackage{tikz}

\begin{document}

\begin{animateinline}[autoplay,loop]{10}
    \multiframe{36}{n=1+1}{
        \begin{tikzpicture}[scale=2]
            % Coordinate network
%           \draw[help lines,step=0.5cm,ultra thin] (-1.45,-1.45) grid (1.45,1.45);
            \draw[->] (-1.75,0) -- (1.75,0);
            \draw[->] (0,-1.75) -- (0,1.75);
            % Rotation arc
            \draw[->, ultra thick,rotate around={\n*10:(0,0)}] (1,0) arc [start angle=0, end angle=180, radius=1];
            \draw[->, ultra thick,rotate around={\n*10:(0,0)}] (-1,0) arc [start angle=-180, end angle=0, radius=1];
            % Stuff
            \fill[red,rotate around={\n*10:(0,0)}] (-0.25,1) rectangle node (source) [black,fill=white, semitransparent, text opacity=1] {X-ray} +(0.5,0.5);
            \fill[green] (-0.25,-0.25) rectangle node [black,fill=white, semitransparent, text opacity=1] {Sample} +(0.5,0.5) ;
            \fill[blue,fill,rotate around={\n*10:(0,0)}] (-0.5,-1.25) rectangle node (detector) [black,fill=white, semitransparent, text opacity=1] {Detector} +(1,0.25);
            \draw[rotate around={\n*10:(0,0)}] (-0.5,-1) node (edgeleft) {L};
            \draw[rotate around={\n*10:(0,0)}] (0.5,-1) node (edgeright) {R};           
            % Cone, based on section 4.1.5 in pgfmanual.pdf
            \pgfdeclarelayer{background}
            \pgfsetlayers{background,main}
            \coordinate (A) at (-0,1);
            \coordinate (B) at (-0.25,-1);
            \coordinate (C) at (0.25,-1);       
            \begin{pgfonlayer}{background}
                \fill[blue,semitransparent] (A) -- (B) -- (C) -- cycle;
                \fill[gray,semitransparent] (source) -- (B) -- (C) -- cycle;
                \fill[green, ultra thick] (source) -- (edgeleft) -- (edgeright) -- cycle;
                \draw [red] (source) -- (detector);
            \end{pgfonlayer}
        \end{tikzpicture}
    }
\end{animateinline}

\end{document}

我觉得我应该能够从source探测器的两个边缘绘制一个多边形(正如我在代码中尝试过的,注释掉了),但这并不起作用。

绘制

  • (红色)旋转铅笔光束(红色)
  • (蓝色)基于代码中的三个坐标的“静态”锥体(直接来自手册:))
  • 以及从源到探测器起始位置的(灰色)移动锥体

一切正常,但是我需要一个移动的锥体指向source的边缘detector。我唯一能做到的就是一条 (绿) 线指向edgeleft。这条绿线非常细,而且只在编译的 PDF 中可见...

有人可以给我提供一些关于如何使用rotate around灰色锥体的见解吗?

在此处输入图片描述

PS1:动画 gif 是用 ImageMagick 导出的,此命令

PS2:动画的样式还未最终完成,但首先我需要旋转:)

答案1

首先定义层,然后使用选项将其余部分放入范围中[rotate around={\n*10:(0,0)}]

\documentclass[export]{standalone}
\usepackage{animate}
\usepackage{tikz}
\begin{document}
\begin{animateinline}[autoplay,loop]{10}
    \multiframe{36}{n=1+1}{
        \begin{tikzpicture}[scale=2]
            \pgfdeclarelayer{background}
            \pgfsetlayers{background,main}
            \draw[->] (-1.75,0) -- (1.75,0);
            \draw[->] (0,-1.75) -- (0,1.75);
            \fill[green] (-0.25,-0.25) rectangle node [black,fill=white, semitransparent, text opacity=1] {Sample} +(0.5,0.5) ;
            \begin{scope}[rotate around={\n*10:(0,0)}]
               \draw[->, ultra thick] (1,0) arc [start angle=0, end angle=180, radius=1];
               \draw[->, ultra thick] (-1,0) arc [start angle=-180, end angle=0, radius=1];
               \fill[red] (-0.25,1) rectangle node (source) [black,fill=white, semitransparent, text opacity=1] {X-ray} +(0.5,0.5);
               \fill[blue,fill] (-0.5,-1.25) rectangle node (detector) [black,fill=white, semitransparent, text opacity=1] {Detector} +(1,0.25);
               \draw (-0.5,-1) node (edgeleft) {L};
               \draw (0.5,-1) node (edgeright) {R};           
               \coordinate (A) at (-0,1);
               \coordinate (B) at (-0.25,-1);
               \coordinate (C) at (0.25,-1);       
               \begin{pgfonlayer}{background}
                   %\fill[blue,semitransparent] (A) -- (B) -- (C) -- cycle;
                   \fill[gray,semitransparent] (source) -- (B) -- (C) -- cycle;
                   \fill[green, ultra thick] (source) -- (edgeleft) -- (edgeright) -- cycle;
                   \draw [red] (source) -- (detector);
               \end{pgfonlayer}
            \end{scope}
        \end{tikzpicture}
    }
\end{animateinline}
\end{document}

在此处输入图片描述

答案2

三角形(A)--(B)--(C)--cycle(source)--(B)--(C)--cycle由于坐标未旋转,因此无法得到所需的结果。使用

\coordinate[rotate around={\n*10:(sample)}] (A) at (-0,1);
\coordinate[rotate around={\n*10:(sample)}] (B) at (-0.25,-1);
\coordinate[rotate around={\n*10:(sample)}] (C) at (0.25,-1);       

三角形的问题(source) -- (edgeleft) -- (edgeright) -- cycle在于它不构成封闭路径。可以使用以下方法修复

\fill[green, ultra thick] (source) -- (edgeleft.west) -- (edgeright.east) -- cycle;

或者在检测器处定义一个节点,然后使用它的锚点来绘制锥体。

\node[rotate around={\n*10:(sample)}, minimum width=1cm] at (0,-1.125) (det){} ;
 %
\fill[gray,semitransparent] (source) -- (det.north east) -- (det.north west) -- cycle;

在此处输入图片描述

\documentclass[export]{standalone}
\usepackage{animate}
\usepackage{tikz}

\begin{document}

\begin{animateinline}[autoplay,loop]{10}
    \multiframe{36}{n=1+1}{
        \begin{tikzpicture}[scale=2]
            \draw[->] (-1.75,0) -- (1.75,0);
            \draw[->] (0,-1.75) -- (0,1.75);
            % Rotation arc
            \draw[->, ultra thick,rotate around={\n*10:(0,0)}] (1,0) arc [start angle=0, end angle=180, radius=1];
            \draw[->, ultra thick,rotate around={\n*10:(0,0)}] (-1,0) arc [start angle=-180, end angle=0, radius=1];
            % Stuff
            \fill[red,rotate around={\n*10:(0,0)}] (-0.25,1) rectangle node (source) [black,fill=white, semitransparent, text opacity=1] {X-ray} +(0.5,0.5);
            \fill[green] (-0.25,-0.25) rectangle node [black,fill=white, semitransparent, text opacity=1] (sample){Sample} +(0.5,0.5) ;
            \node[rotate around={\n*10:(sample)}, minimum width=1cm] at (0,-1.125) (det){} ;
            \node[rotate around={\n*10:(sample)}] at (0, 1.125) (src){} ;            
            \fill[blue,fill,rotate around={\n*10:(0,0)}] (-0.5,-1.25) rectangle node (detector) [black,fill=white, semitransparent, text opacity=1] {Detector} +(1,0.25);
            \draw[rotate around={\n*10:(0,0)}] (-0.5,-1) node (edgeleft) {L};
            \draw[rotate around={\n*10:(0,0)}] (0.5,-1) node (edgeright) {R};           
            % Cone, based on section 4.1.5 in pgfmanual.pdf
            \pgfdeclarelayer{background}
            \pgfsetlayers{background,main}
            \begin{pgfonlayer}{background}
                \fill[gray,semitransparent] (src.south) -- (det.north east) -- (det.north west) -- cycle;
                \draw [red] (src.south) -- (det);
            \end{pgfonlayer}
        \end{tikzpicture}
    }
\end{animateinline}

\end{document}

PS:请注意,我做了一些更改,以使红线与锥体对齐。

相关内容