You were almost there. Drawing a plane is as simple as saying
\draw[canvas is xy plane at z=2,fill=blue,fill opacity=0.6] (-4,-4) rectangle (4,4);
Other than that you need to draw the parts of the cone below and above the planes separately, which is why I added a macro for the truncated cone, \conetruncfront
. I also replaced the hardcoded 45
with \tdplotmainphi
.
\documentclass[tikz, border=3pt]{standalone}
\usepackage{tikz,tikz-3dplot}
\tdplotsetmaincoords{80}{45}
%% style for surfaces
\tikzset{surface/.style={draw=black, fill=white, fill opacity=.6}}
%% macros to draw back and front of cones
%% optional first argument is styling; others are z, radius, side offset (in degrees)
\newcommand{\coneback}[4][]{
%% start at the correct point on the circle, draw the arc, then draw to the origin of the diagram, then close the path
\draw[canvas is xy plane at z=#2, #1] (\tdplotmainphi-#4:#3)
arc(\tdplotmainphi-#4:\tdplotmainphi+180+#4:#3) -- (O) --cycle;
}
\newcommand{\conefront}[4][]{
\draw[canvas is xy plane at z=#2, #1] (\tdplotmainphi-#4:#3) arc
(\tdplotmainphi-#4:\tdplotmainphi-180+#4:#3) -- (O) --cycle;
}
\newcommand{\conetruncfront}[6][]{
\draw[line join=round,#1] plot[variable=\t,domain=\tdplotmainphi-#4:\tdplotmainphi-180+#4]
({#3*cos(\t)},{#3*sin(\t)},#2)
-- plot[variable=\t,domain=\tdplotmainphi-180-#4:\tdplotmainphi+#4]
({#6*cos(\t)},{#6*sin(\t)},#5)
--cycle;
}
\begin{document}
\begin{tikzpicture}[tdplot_main_coords]
\coordinate (O) at (0,0,0);
%% make sure to draw everything from back to front
\coneback[surface]{-3}{2}{-10}
\draw (0,0,-5) -- (O);
\conefront[surface]{-3}{2}{-10}
\draw[canvas is xy plane at z=-2,fill=green!60!black,fill opacity=0.6] (-4,-4) rectangle (4,4);
\coneback[surface]{-2}{4/3}{-10}
\draw (0,0,-2) -- (O);
\conefront[surface]{-2}{4/3}{-10}
\draw[canvas is xy plane at z=0,fill=blue,fill opacity=0.6] (-4,-4) rectangle (4,4);
\draw[->] (-6,0,0) -- (6,0,0) node[right] {$x$};
\draw[->] (0,-6,0) -- (0,6,0) node[right] {$y$};
\coneback[surface]{3}{2}{10}
\draw[->] (O) -- (0,0,5) node[above] {$z$};
\conefront[surface]{3}{2}{10}
\draw[canvas is xy plane at z=2,fill=purple,fill opacity=0.6] (-4,-4) rectangle (4,4);
\draw[->] (0,0,2) -- (0,0,5) node[above] {$z$};
\conetruncfront[surface]{2}{4/3}{0}{3}{2}
\end{tikzpicture}
\end{document}
However, I'd slightly change things to get
\documentclass[tikz, border=3pt]{standalone}
\usepackage{tikz,tikz-3dplot}
\tdplotsetmaincoords{80}{45}
%% style for surfaces
\tikzset{surface/.style={draw=black, left color=yellow,right color=yellow,middle
color=yellow!60!#1, fill opacity=.6},surface/.default=white}
%% macros to draw back and front of cones
%% optional first argument is styling; others are z, radius, side offset (in degrees)
\newcommand{\coneback}[4][]{
%% start at the correct point on the circle, draw the arc, then draw to the origin of the diagram, then close the path
\draw[canvas is xy plane at z=#2, #1] (\tdplotmainphi-#4:#3)
arc(\tdplotmainphi-#4:\tdplotmainphi+180+#4:#3) -- (O) --cycle;
}
\newcommand{\conefront}[4][]{
\draw[canvas is xy plane at z=#2, #1] (\tdplotmainphi-#4:#3) arc
(\tdplotmainphi-#4:\tdplotmainphi-180+#4:#3) -- (O) --cycle;
}
\newcommand{\conetruncback}[6][]{
\draw[line join=round,#1] plot[variable=\t,domain=\tdplotmainphi-#4:\tdplotmainphi+180+#4]
({#3*cos(\t)},{#3*sin(\t)},#2)
-- plot[variable=\t,domain=\tdplotmainphi+180-#4:\tdplotmainphi+#4]
({#6*cos(\t)},{#6*sin(\t)},#5)
--cycle;
}
\newcommand{\conetruncfront}[6][]{
\draw[line join=round,#1] plot[variable=\t,domain=\tdplotmainphi-#4:\tdplotmainphi-180+#4]
({#3*cos(\t)},{#3*sin(\t)},#2)
-- plot[variable=\t,domain=\tdplotmainphi-180-#4:\tdplotmainphi+#4]
({#6*cos(\t)},{#6*sin(\t)},#5)
--cycle;
}
\begin{document}
\begin{tikzpicture}[tdplot_main_coords]
\coordinate (O) at (0,0,0);
\conetruncback[surface=black]{-2}{4/3}{0}{-3}{2}
\draw (0,0,-5) -- (0,0,-2);
\conetruncfront[surface]{-2}{4/3}{0}{-3}{2}
\draw[canvas is xy plane at z=-2,fill=green!60!black,fill opacity=0.6] (-4,-4) rectangle (4,4);
\coneback[surface=black]{-2}{4/3}{-10}
\draw (0,0,-2) -- (O);
\conefront[surface]{-2}{4/3}{-10}
\draw[canvas is xy plane at z=0,fill=blue,fill opacity=0.6] (-4,-4) rectangle (4,4);
\draw[->] (-6,0,0) -- (6,0,0) node[right] {$x$};
\draw[->] (0,-6,0) -- (0,6,0) node[right] {$y$};
\coneback[surface=white]{2}{4/3}{10}
\draw[-] (O) -- (0,0,2);
\conefront[surface=black]{2}{4/3}{10}
\draw[canvas is xy plane at z=2,fill=purple,fill opacity=0.6] (-4,-4) rectangle (4,4);
\conetruncback[surface=white]{2}{4/3}{0}{3}{2}
\draw[->] (0,0,2) -- (0,0,5) node[above] {$z$};
\conetruncfront[surface=black]{2}{4/3}{0}{3}{2}
\end{tikzpicture}
\end{document}
Or with slightly different view angles and opacity set to 1, and adjustments suggested by minhthien_2016.
\documentclass[tikz, border=3pt]{standalone}
\usepackage{tikz,tikz-3dplot}
\tdplotsetmaincoords{80}{60}
%% style for surfaces
\tikzset{surface/.style={draw=black, left color=yellow,right color=yellow,middle
color=yellow!60!#1, fill opacity=1},surface/.default=white}
%% macros to draw back and front of cones
%% optional first argument is styling; others are z, radius, side offset (in degrees)
\newcommand{\coneback}[4][]{
%% start at the correct point on the circle, draw the arc, then draw to the origin of the diagram, then close the path
\draw[canvas is xy plane at z=#2, #1] (\tdplotmainphi-#4:#3)
arc(\tdplotmainphi-#4:\tdplotmainphi+180+#4:#3) -- (O) --cycle;
}
\newcommand{\conefront}[4][]{
\draw[canvas is xy plane at z=#2, #1] (\tdplotmainphi-#4:#3) arc
(\tdplotmainphi-#4:\tdplotmainphi-180+#4:#3) -- (O) --cycle;
}
\newcommand{\conetruncback}[7][]{
\draw[line join=round,#1] plot[variable=\t,domain=\tdplotmainphi-#4:\tdplotmainphi+180+#4]
({#3*cos(\t)},{#3*sin(\t)},#2)
-- plot[variable=\t,domain=\tdplotmainphi+180-#7:\tdplotmainphi+#7]
({#6*cos(\t)},{#6*sin(\t)},#5)
--cycle;
}
\newcommand{\conetruncfront}[7][]{
\draw[line join=round,#1] plot[variable=\t,domain=\tdplotmainphi-#4:\tdplotmainphi-180+#4]
({#3*cos(\t)},{#3*sin(\t)},#2)
-- plot[variable=\t,domain=\tdplotmainphi-180-#7:\tdplotmainphi+#7]
({#6*cos(\t)},{#6*sin(\t)},#5)
--cycle;
}
\begin{document}
\begin{tikzpicture}[tdplot_main_coords]
\coordinate (O) at (0,0,0);
\conetruncback[surface=black]{-2}{4/3}{-5}{-3}{2}{5}
\draw (0,0,-5) -- (0,0,-2);
\conetruncfront[surface]{-2}{4/3}{-5}{-3}{2}{5}
\draw[canvas is xy plane at z=-2,fill=green!60!black,fill opacity=1] (-4,-4) rectangle (4,4);
\coneback[surface=black]{-2}{4/3}{-10}
\draw (0,0,-2) -- (O);
\conefront[surface]{-2}{4/3}{-10}
\draw[canvas is xy plane at z=0,fill=blue,fill opacity=1] (-4,-4) rectangle (4,4);
\draw[->] (-6,0,0) -- (6,0,0) node[right] {$x$};
\draw[->] (0,-6,0) -- (0,6,0) node[right] {$y$};
\coneback[surface=white]{2}{4/3}{10}
\draw[-] (O) -- (0,0,2);
\conefront[surface=black]{2}{4/3}{10}
\draw[canvas is xy plane at z=2,fill=purple,fill opacity=1] (-4,-4) rectangle (4,4);
\conetruncback[surface=white]{2}{4/3}{5}{3}{2}{-5}
\draw[->] (0,0,2) -- (0,0,5) node[above] {$z$};
\conetruncfront[surface=black]{2}{4/3}{5}{3}{2}{-5}
\end{tikzpicture}
\end{document}
With TikZ this is easy to draw using pic
s, style
s and the 3d
library:
\documentclass[tikz,border=2mm]{standalone}
\usetikzlibrary{3d}
\tikzset
{%
front face/.style={fill=gray!20,canvas is xy plane at z=1},
up face/.style={fill=gray!50,canvas is xz plane at y=1},
east face/.style={fill=gray!80,canvas is yz plane at x=1},
pics/square/.style={
code={\draw[fill=white,even odd rule] (0,0) rectangle (3,3) (1,1) rectangle (2,2);}},
}
\begin{document}
\begin{tikzpicture}
\foreach\i in {0,1} \foreach\s in {front face, up face, east face}
\draw[\s] (\i,1-\i) rectangle ++(1,1);
\foreach\i in {1,2} \foreach\s in {front face, up face, east face}
\draw[\s] (\i,3-\i) rectangle ++(1,1);
\pic[canvas is xy plane at z=3] {square};
\pic[canvas is xz plane at y=3] {square};
\pic[canvas is yz plane at x=3] {square};
\end{tikzpicture}
\end{document}
Update: An animated version. I shifted all the points and changed the perspective, but the rest is the same:
\documentclass {beamer}
\usepackage {tikz}
\usetikzlibrary {3d,perspective}
% beamer configuration
\setbeamertemplate {navigation symbols}{}
\tikzset
{%
up face/.style={fill=gray!30,canvas is xy plane at z=-0.5},
pics/square/.style={code={\draw[fill=white,even odd rule] (-1.5,-1.5) rectangle (1.5,1.5)
(-0.5,-0.5) rectangle (0.5,0.5);}},
}
\begin{document}
\begin{frame}
\foreach\i in{1,...,18}
{
\only<\i>
{
\begin{figure}\centering
\begin{tikzpicture}[line cap=round,line join=round,isometric view,rotate around z=5*\i-45]
\pgfmathsetmacro\lc{50+2*\i} % left color proportion
\pgfmathsetmacro\rc{86-2*\i} % right color proportion
\tikzset
{
left face/.style={fill=gray!\lc,canvas is xz plane at y=0.5},
right face/.style={fill=gray!\rc,canvas is yz plane at x=0.5},
}
\useasboundingbox (0,0) circle (3cm);
\draw[thick,red] (0,0,-4) -- (0,0,-1.5);
\foreach\i in {0,1}
{
\draw[up face] (0.5-\i,-0.5+\i) rectangle ++(1,1);
\draw[left face] (0.5-\i,-0.5-\i) rectangle ++(1,1);
\draw[right face] (0.5-\i,-0.5-\i) rectangle ++(1,1);
}
\draw[thick,red] (0,0,-1.5) -- (0,0,-0.5);
\foreach\i in {0,1}
{
\draw[up face] (-1.5+\i,-0.5-\i) rectangle ++(1,1);
\draw[left face] (-1.5+\i,-0.5+\i) rectangle ++(1,1);
\draw[right face] (-1.5+\i,-0.5+\i) rectangle ++(1,1);
}
\draw[thick,red] (0,0,-0.5) -- (0,0,1.5);
\pic[canvas is xy plane at z= 1.5] at (0,0) {square};
\pic[canvas is xz plane at y=-1.5] at (0,0) {square};
\pic[canvas is yz plane at x=-1.5] at (0,0) {square};
\draw[thick,red] (0,0,1.5) -- (0,0,4);
\end{tikzpicture}
\end{figure}
}
}
\end{frame}
\end{document}
Best Answer
You can you 3dtools. Some calculations can be found by
3dtools
.With
phi=5
,