Rotate triangle based on named coordinates [TikZ]
Define the layers first and then put the rest into a scope with the option [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}
Triangle (A)--(B)--(C)--cycle
and (source)--(B)--(C)--cycle
does not give the desired result because coordinates are not rotated. Fix it with
\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);
Problem with the triangle (source) -- (edgeleft) -- (edgeright) -- cycle
is that it does not form a closed path. Can be fixed with
\fill[green, ultra thick] (source) -- (edgeleft.west) -- (edgeright.east) -- cycle;
Alternatively define a node at detector and then use its anchors to draw the cone.
\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: Note that I have made some changes to make the red line align with the cone.