我想绘制三个圆锥曲线(圆、椭圆和矩形),其中圆柱体和横截面都是彩色的:
\documentclass{standalone}
\usepackage{tikz}
\usepackage{animate}
\usepackage{filecontents}
\begin{document}
\begin{filecontents}{time2.txt}
::0x0
::1
::2
::3
\end{filecontents}
\begin{animateinline}[
begin={
\begin{tikzpicture}[line cap=round,line join=round,x=1.0cm,y=1.0cm,scale=0.6]
\clip(-3,0) rectangle (6,6);
},
end={\end{tikzpicture}},
controls,timeline=time2.txt]{1}
\draw [rotate around={0.:(1.5,1.)},line width=1.pt] (1.5,1.) ellipse (1.5897934007793624cm and 0.5267286371193529cm);
\draw [rotate around={0.:(1.5,5.)},line width=1.pt] (1.5,5.) ellipse (1.5897934007793588cm and 0.5267286371193518cm);
\draw [line width=1.pt] (-0.089793400779358,5.)-- (-0.089793400779362,1.);
\draw [line width=1.pt] (3.089793400779359,5.)-- (3.0897934007793624,1.);
\newframe %elipse
\draw [rotate around={-22.21759426951831:(1.5,3.14)},line width=1.pt,color=blue,fill=blue,fill opacity=0.2] (1.5,3.14) ellipse (1.6601578476760366cm and 0.6350780103265238cm);
\newframe %circunferencia
\draw [line width=1.pt] (3.089793400779359,5.)-- (3.0897934007793624,1.);
\draw [line width=1.pt,color=green,fill=green,fill opacity=0.2] (1.5,3) ellipse (1.57 and 0.6);
\newframe %rectangulo
\draw [line width=1.pt] (3.089793400779359,5.)-- (3.0897934007793624,1.);
\draw [line width=1.pt,color=orange,fill=orange,fill opacity=0.2](0.4,5.38) -- (0.39,1.38) -- (2.63,0.63) -- (2.62,4.63) -- cycle;
\end{animateinline}
\end{document}
答案1
以下是基于 的一些代码tikz-3dplot
,用于修复视图。这是通过命令\tdplotsetmaincoords{70}{\X}
,然后完成的\begin{scope}[tdplot_main_coords]
。此外,3d
库用于xy
在不同z
值下切换平面。
\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{tikz-3dplot}
\usetikzlibrary{3d,backgrounds}
% small fix for canvas is xy plane at z % https://tex.stackexchange.com/a/48776/121799
\makeatletter
\tikzoption{canvas is xy plane at z}[]{%
\def\tikz@plane@origin{\pgfpointxyz{0}{0}{#1}}%
\def\tikz@plane@x{\pgfpointxyz{1}{0}{#1}}%
\def\tikz@plane@y{\pgfpointxyz{0}{1}{#1}}%
\tikz@canvas@is@plane}
\makeatother
\begin{document}
\foreach \X in {5,15,...,355}
{\tdplotsetmaincoords{70}{\X}
\begin{tikzpicture}[declare function={h(\x,\y)=2+0.5*(\y+\y*cos(\x));}]
\path[use as bounding box] (-4,-2) rectangle (18,10);
\begin{scope}
\begin{scope}[tdplot_main_coords]
\begin{scope}[canvas is xy plane at z=0]
\path[fill=orange!50] (0,0) circle (3);
\coordinate (bl) at (0+\tdplotmainphi:3);
\coordinate (br) at (180+\tdplotmainphi:3);
\draw[dashed] (bl) arc(0+\tdplotmainphi:180+\tdplotmainphi:3);
\draw[thick] (br) arc(180+\tdplotmainphi:360+\tdplotmainphi:3);
\coordinate (rbl) at (0:3);
\coordinate (rbr) at (180:3);
\end{scope}
\begin{scope}[canvas is xy plane at z=8]
\draw[thick,fill=orange!30] (0,0) circle (3);
\coordinate (tl) at (0+\tdplotmainphi:3);
\coordinate (tr) at (180+\tdplotmainphi:3);
\coordinate (rtl) at (0:3);
\coordinate (rtr) at (180:3);
\end{scope}
\begin{scope}[on background layer]
\fill[orange!20] (bl) rectangle (tr);
\end{scope}
\begin{scope}[canvas is xy plane at z=4]
\path[fill=blue,opacity=0.3] (0,0) circle (3);
\end{scope}
\end{scope}
\end{scope}
\begin{scope}[xshift=7cm]
\begin{scope}[tdplot_main_coords]
\begin{scope}[canvas is xy plane at z=0]
\path[fill=orange!50] (0,0) circle (3);
\coordinate (bl) at (0+\tdplotmainphi:3);
\coordinate (br) at (180+\tdplotmainphi:3);
\draw[dashed] (bl) arc(0+\tdplotmainphi:180+\tdplotmainphi:3);
\draw[thick] (br) arc(180+\tdplotmainphi:360+\tdplotmainphi:3);
\coordinate (rbl) at (0:3);
\coordinate (rbr) at (180:3);
\end{scope}
\begin{scope}[canvas is xy plane at z=8]
\draw[thick,fill=orange!30] (0,0) circle (3);
\coordinate (tl) at (0+\tdplotmainphi:3);
\coordinate (tr) at (180+\tdplotmainphi:3);
\coordinate (rtl) at (0:3);
\coordinate (rtr) at (180:3);
\end{scope}
\begin{scope}[on background layer]
\fill[orange!20] (bl) rectangle (tr);
\end{scope}
\fill[green!60!black,opacity=0.3] plot[variable=\x,domain=-180:180,samples=90] ({3*cos(\x)},{3*sin(\x)},{h(\x,3)});
\end{scope}
\end{scope}
\begin{scope}[xshift=14cm]
\begin{scope}[tdplot_main_coords]
\begin{scope}[canvas is xy plane at z=0]
\path[fill=orange!50] (0,0) circle (3);
\coordinate (bl) at (0+\tdplotmainphi:3);
\coordinate (br) at (180+\tdplotmainphi:3);
\draw[dashed] (bl) arc(0+\tdplotmainphi:180+\tdplotmainphi:3);
\draw[thick] (br) arc(180+\tdplotmainphi:360+\tdplotmainphi:3);
\coordinate (rbl) at (0:3);
\coordinate (rbr) at (180:3);
\end{scope}
\begin{scope}[canvas is xy plane at z=8]
\draw[thick,fill=orange!30] (0,0) circle (3);
\coordinate (tl) at (0+\tdplotmainphi:3);
\coordinate (tr) at (180+\tdplotmainphi:3);
\coordinate (rtl) at (0:3);
\coordinate (rtr) at (180:3);
\end{scope}
\begin{scope}[on background layer]
\fill[orange!20] (bl) rectangle (tr);
\end{scope}
\fill[red,opacity=0.3] (rtl) -- (rtr) -- (rbr) -- (rbl);
\end{scope}
\end{scope}
\end{tikzpicture}
}
\end{document}
答案2
我与大家分享我的构造,感谢marmot。
\documentclass{standalone}
\usepackage{tikz}
\usepackage{tikz-3dplot}
\usetikzlibrary{3d,backgrounds}
\usepackage{animate}
\usepackage{filecontents}
\begin{document}
\begin{filecontents}{time.txt}
::0x0
::1
::2
::3
\end{filecontents}
\tdplotsetmaincoords{70}{0}
\begin{animateinline}[
begin={
\begin{tikzpicture}[declare function={h(\x,\y)=2+0.5*(\y+\y*cos(\x));}];
\path[use as bounding box] (-2.2,-1) rectangle (2.5,6.5);
},
end={\end{tikzpicture}},
controls,timeline=time.txt]{1}
\begin{scope}[tdplot_main_coords]
%base inferior
\begin{scope}[canvas is xy plane at z=0]
\path[fill=orange!50] (0,0) circle (2);
\coordinate (bl) at (0:2);
\coordinate (br) at (180:2);
\draw[dashed] (bl) arc(0:180:2);
\draw[thick] (br) arc(180:360:2);
%rectangulo
\coordinate (rbl) at (60:2);
\coordinate (rbr) at (240:2);
\end{scope}
%Base superior
\begin{scope}[canvas is xy plane at z=6]
\draw[thick,fill=orange!30] (0,0) circle (2);
\coordinate (tl) at (0:2);
\coordinate (tr) at (180:2);
%rectangulo
\coordinate (rtl) at (60:2);
\coordinate (rtr) at (240:2);
\end{scope}
%superficie lateral
\begin{scope}[on background layer]
\fill[orange!20] (bl) rectangle (tr);
\end{scope}
\end{scope}
\newframe %circulo
\begin{scope}[tdplot_main_coords]
\begin{scope}[canvas is xy plane at z=3]
\path[fill=blue,opacity=0.3] (0,0) circle (2);
\end{scope}
\end{scope}
\newframe %elipse
\begin{scope}[tdplot_main_coords]
\fill[green!60!black,opacity=0.3] plot[variable=\x,domain=-180:180,samples=90] ({2*cos(\x)},{2*sin(\x)},{h(\x,2)});
\end{scope}
\newframe %rectangulo
\begin{scope}[tdplot_main_coords]
\fill[red,opacity=0.3] (rtl) -- (rtr) -- (rbr) -- (rbl);
\end{scope}
\end{animateinline}
\end{document}