2

I have prepared a 3D drawing using tikz-3dplot and now I want to clip a specific part of this drawing in order to magnify it (focus on the circle for instance in the example below). Is there any simple way to do this? Is it possible to define a 2D layer above the 3D drawing to achieve the clipping?

MWE:

\documentclass[a4paper]{article}

\usepackage{tikz,tikz-3dplot}
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}


\begin{document} 

\tdplotsetmaincoords{70}{110}
\begin{tikzpicture}[tdplot_main_coords]
    \draw[thick,->] (0,0,0) -- (1,0,0) node[anchor=north east]{$x$};
    \draw[thick,->] (0,0,0) -- (0,1,0) node[anchor=north west]{$y$};
    \draw[thick,->] (0,0,0) -- (0,0,1) node[anchor=south]{$z$};
    %
    \draw[fill] (10,10,5) circle (10pt);
    \draw[help lines](-1,-1) grid (10,10);
    \path[clip,draw] (5,5)--(12,12); 
\end{tikzpicture}
\end{document}
3

I'm not sure about "defining a 2D layer above a 3D drawing," but perhaps this is what you want to achieve? Use the same code twice, wrap the second instance within a scope using shift and scale, then use clip within scope to isolate the desired area.

\documentclass[a4paper]{article}

\usepackage{tikz,tikz-3dplot}
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}

\begin{document} 

\tdplotsetmaincoords{70}{110}
\begin{tikzpicture}[tdplot_main_coords]
% Original drawing
    \draw[thick,->] (0,0,0) -- (1,0,0) node[anchor=north east]{$x$};
    \draw[thick,->] (0,0,0) -- (0,1,0) node[anchor=north west]{$y$};
    \draw[thick,->] (0,0,0) -- (0,0,1) node[anchor=south]{$z$};
    %
    \draw[fill] (10,10,5) circle (10pt);
    \draw[help lines](-1,-1) grid (10,10);
%    \path[clip,draw] (5,5)--(12,12); 
    \draw[red] (10,9.5,4.5) circle (30pt);
% Zoomed in piece
\begin{scope}[shift={(-1,-10,-4)},scale=2]
\draw[fill=white,draw=red] (10,9.5,4.5) circle (30pt);
\clip (10,9.5,4.5) circle (30pt);
    \draw[thick,->] (0,0,0) -- (1,0,0) node[anchor=north east]{$x$};
    \draw[thick,->] (0,0,0) -- (0,1,0) node[anchor=north west]{$y$};
    \draw[thick,->] (0,0,0) -- (0,0,1) node[anchor=south]{$z$};
    %
    \draw[fill] (10,10,5) circle (10pt);
    \draw[help lines](-1,-1) grid (10,10);
%    \path[clip,draw] (5,5)--(12,12); 
\end{scope}
\end{tikzpicture}
\end{document}

I commented out your line \path[clip,draw], but you can put it back in after the scope. This is the output:

enter image description here


EDIT: To be able to move around the magnified piece in 2D coordinates, place both pieces of the drawing in their own scopes, as below. I won't repeat the code inside the scopes, but it's the same as above, respectively.

\tdplotsetmaincoords{70}{110}
\begin{tikzpicture}
\begin{scope}[tdplot_main_coords]
% Original drawing
\end{scope}
\begin{scope}[shift={(-9,-2.5)},scale=2,tdplot_main_coords]
% Zoomed in piece
\end{scope}
\end{tikzpicture}
  • Thank you for your presentation. Is there any way to locate precisely the center of the cirle on the 2D grid? Here you use 3D coordinates which are not always easy to determinate. – Guuk Nov 19 at 14:01
  • @Guuk edited, see update. – Jānis Lazovskis Nov 19 at 14:22
  • Ok very simple :-) Thank you very much!! – Guuk Nov 19 at 14:26
3

The spy library described from page 818 of the TikZ 3.1.4b manual is designed to do this.

screenshot

\documentclass[a4paper]{article}

\usepackage{tikz,tikz-3dplot}
\usetikzlibrary{spy}
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}


\begin{document} 

\tdplotsetmaincoords{70}{110}
\begin{tikzpicture}[tdplot_main_coords,spy using outlines={circle, magnification=3, size=2cm, connect spies}]
    \draw[thick,->] (0,0,0) -- (1,0,0) node[anchor=north east]{$x$};
    \draw[thick,->] (0,0,0) -- (0,1,0) node[anchor=north west]{$y$};
    \draw[thick,->] (0,0,0) -- (0,0,1) node[anchor=south]{$z$};
    %
    \draw[fill] (10,10,5) circle (10pt);
    \draw[help lines](-1,-1) grid (10,10);
    \spy [green!50!black] on (0,1,0) in node at (.5,-2,-2);
    \spy [green!50!black] on (0,6,1) in node at (.5,8,-1);
    %\path[clip,draw] (5,5)--(12,12); 
\end{tikzpicture}
\end{document}
1

My interpretation of the question is that you are looking for something like this: you want to zoom in using a bird's eye.

\documentclass[a4paper]{article}

\usepackage{tikz,tikz-3dplot}
\usetikzlibrary{spy}
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}


\begin{document} 

\tdplotsetmaincoords{70}{110}
\begin{tikzpicture}[tdplot_main_coords,
    spy using outlines={circle, magnification=4, size=2.5cm, connect spies,red}]
    \draw[thick,->] (0,0,0) -- (1,0,0) node[anchor=north east]{$x$};
    \draw[thick,->] (0,0,0) -- (0,1,0) node[anchor=north west]{$y$};
    \draw[thick,->] (0,0,0) -- (0,0,1) node[anchor=south]{$z$};
    %
    \draw[fill] (6,6,0) circle (10pt);
    \begin{scope}[canvas is xy plane at z=0,transform shape]
     \draw[help lines](-1,-1) grid (10,10);
     \node [circle,inner sep=8pt] (p1) at (0,1) {};
     \node [circle,inner sep=8pt] (p2) at (6.2,6) {};
    \pgfgettransform{\mytrafo} % read off transformation
    \xdef\mytrafo{\mytrafo} % globalize macro
    \end{scope}
   \begin{scope}[tdplot_screen_coords]
    \path (1,3) coordinate (L1) (4,3) coordinate (L2); 
    \spy[
    lens={/utils/exec={\pgfsettransform{\mytrafo} % reinstall and invert trafo
    \pgftransforminvert},scale=3}
    ] on (p1) in node at (L1);

    \spy[
    lens={/utils/exec={\pgfsettransform{\mytrafo} % reinstall and invert trafo
    \pgftransforminvert},scale=3}
    ] on (p2) in node at (L2);
  \end{scope}
\end{tikzpicture}
\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.