TikZ(3d+透视),动画方位角序列中的固定原点

TikZ(3d+透视),动画方位角序列中的固定原点

我正在尝试选择一个好的角度来显示一个通过原点且不接触正象限中任何点的平面。然后,我将其制作成动画。是否可以在动画中固定原点?假设 OZ 在动画的每一帧中都是固定的,原点位于屏幕上的同一点。

\documentclass[dvisvgm]{standalone}  %for svg
%\documentclass[export]{standalone}  %for pdf -> gif
\usepackage{tikz,xcolor}
\usepackage{graphicx}
\usepackage[draft]{animate}
\usetikzlibrary{3d,calc,perspective}

\begin{document}

\newcommand{\BM}[3]{
\def\U{#1}  %u
\def\D{#2}  %d
\def\R{#3}  %R_0
}

\BM{1.2}{0.9}{1.125}

\begin{animateinline}[final,controls={play},loop]{5}
\multiframe{71}{iAngle=5+5}{
%% \foreach \iAngle in {5,10,...,355}{
\begin{tikzpicture}[line cap=round,line join=round,
            3d view={\iAngle}{25},
                    scale=2]

%% \useasboundingbox (-2.5,-2.5) rectangle (3,3);

\pgfmathsetmacro{\gu}{(\R-\D)/(\U-\D)/\R}
\pgfmathsetmacro{\gd}{(\U-\R)/(\U-\D)/\R}
\pgfmathsetmacro{\gg}{1+\gu*\gu}
\pgfmathsetmacro{\nu}{1/sqrt(\gg)}
\pgfmathsetmacro{\nd}{\nu/sqrt((\gg+\gd*\gd))}

\coordinate (O)  at (0,0,0);
\coordinate (X)  at (1,0,0);
\coordinate (Y)  at (0,1,0);
\coordinate (Z)  at (0,0,1);
\coordinate (N)  at (\gu,\gd,1);
\coordinate (SPu)  at (1,0,-\gu);
\coordinate (SPd)  at (0,1,-\gd);
\coordinate (ux)  at (1,0,0);
\coordinate (uy)  at (0,1,0);
\coordinate (px)  at ($\nu*(SPu)$);
\coordinate (py)  at ($\nd*(\gd*\gd,-\gg,\gd)$);

\begin{scope}[red!70, plane origin={(O)},plane x={(px)},
    plane y={(py)},canvas is plane]
\filldraw [blue!7!white] (0,0) circle [radius=2];
\node at (1,1) {\iAngle};
%other draws in this plane
\end{scope}


% axes                                              with the desired length
\foreach\i/\j in {X/x,Y/y,Z/z}
{
  \draw[-latex] (O) -- ($(\i)!-1cm!(O)$);       %Distance Modifiers
  \node      at ($(\i)!-1.2cm!(O)$) {$\j$};
}




\filldraw[fill=green!20!white, draw=green!50!black, fill opacity=0.5, draw opacity=0.5] (O)
    -- ($1.5*(ux)$) -- ($1.5*(1,1,0)$) -- ($1.5*(uy)$)  -- cycle;
\filldraw[fill=red!20!white, draw=red!50!black, fill opacity=0.5, draw opacity=0.5] (O)
    -- ($1.5*(uy)$) -- ($1.5*(0,1,1)$) -- ($1.5*(0,0,1)$)  -- cycle;

%% \draw [blue] (current bounding box.south west) rectangle (current bounding box.north east);

\end{tikzpicture}
}
\end{animateinline}



\end{document}

输出如下

改变视角方位角

对于此gif文件:\documentclass[export]{standalone}生成 pdf,并convert -density 300 -delay 8 -loop 0 -background white out.pdf out.gif

答案1

非常感谢亚历克斯。我想我可以解决这个问题:viewport使用https://tex.stackexchange.com/a/638202

\documentclass[export]{standalone}
%% %convert -density 300 -delay 8 -loop 0 -background white  out.pdf out.gif

\usepackage{tikz,xcolor}
\usepackage{graphicx}
\usepackage[draft]{animate}
\usetikzlibrary{3d,calc,perspective}

\begin{document}




\newcommand{\BM}[3]{
\def\U{#1}  %u
\def\D{#2}  %d
\def\R{#3}  %R_0
}

\BM{1.2}{0.9}{1.125}

\tikzset{viewport/.style 2 args={
    x={({cos(-#1)*1cm},{sin(-#1)*sin(#2)*1cm})},
    y={({-sin(-#1)*1cm},{cos(-#1)*sin(#2)*1cm})},
    z={(0,{cos(#2)*1cm})}   }}


%% \begin{animateinline}[final,controls={play},loop]{5}
\begin{animateinline}[final,autoplay,loop]{5}
\multiframe{71}{iAngle=5+5}{
%% \foreach \Angle in {345}{
%% \foreach \Angle in {5,10,...,355}{
\begin{tikzpicture}[line cap=round,line join=round,
                    scale=2]


\path [use as bounding box, draw=none] (0,0) circle [radius=2.57];
\node[red!70] at (2,2) {\iAngle};

\pgfmathsetmacro{\gu}{(\R-\D)/(\U-\D)/\R}
\pgfmathsetmacro{\gd}{(\U-\R)/(\U-\D)/\R}
\pgfmathsetmacro{\gg}{1+\gu*\gu}
\pgfmathsetmacro{\nu}{1/sqrt(\gg)}
\pgfmathsetmacro{\nd}{\nu/sqrt((\gg+\gd*\gd))}

\begin{scope}[viewport={\iAngle}{25}]
\coordinate (O)  at (0,0,0);
\coordinate (X)  at (1,0,0);
\coordinate (Y)  at (0,1,0);
\coordinate (Z)  at (0,0,1);
\coordinate (N)  at (\gu,\gd,1);
\coordinate (SPu)  at (1,0,-\gu);
\coordinate (SPd)  at (0,1,-\gd);
\coordinate (ux)  at (1,0,0);
\coordinate (uy)  at (0,1,0);
\coordinate (px)  at ($\nu*(SPu)$);
\coordinate (py)  at ($\nd*(\gd*\gd,-\gg,\gd)$);


\begin{scope}[red!70, plane origin={(O)},plane x={(px)},
    plane y={(py)},canvas is plane]
\filldraw [blue!7!white] (0,0) circle [radius=2];

\end{scope}

% axes                                              with the desired length
\foreach\i/\j in {X/x,Y/y,Z/z}
{
  \draw[-latex] (O) -- ($(\i)!-1cm!(O)$);       %Distance Modifiers
  \node      at ($(\i)!-1.2cm!(O)$) {$\j$};
}



\filldraw[fill=green!20!white, draw=green!50!black, fill opacity=0.5, draw opacity=0.5] (O)
    -- ($1.5*(ux)$) -- ($1.5*(1,1,0)$) -- ($1.5*(uy)$)  -- cycle;
\filldraw[fill=red!20!white, draw=red!50!black, fill opacity=0.5, draw opacity=0.5] (O)
    -- ($1.5*(uy)$) -- ($1.5*(0,1,1)$) -- ($1.5*(0,0,1)$)  -- cycle;


%% \draw [blue] (current bounding box.south west) rectangle (current bounding box.north east);
\end{scope}
\end{tikzpicture}
}
\end{animateinline}



\end{document}

然后,我们有以下输出 保持 oz 轴恒定

相关内容