围绕给定点缩放 tikz 图片

围绕给定点缩放 tikz 图片

我想围绕给定点缩放 tikz 图片。图片的高度和宽度不应改变,但应以定义的点为中心放大。这是我到目前为止尝试过的方法,但似乎无法正确设置边界框:

\documentclass[a4paper]{article}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[top=2cm,bottom=2cm,hmargin=2cm]{geometry}

\usepackage{tikz}
\usetikzlibrary{calc,decorations.markings}

\tikzset{
tangent/.style={
        decoration={
            markings,% switch on markings
            mark=
                at position #1
                with
                {
                    \coordinate (tangent point-\pgfkeysvalueof{/pgf/decoration/mark info/sequence number}) at (0pt,0pt);
                    \coordinate (tangent unit vector-\pgfkeysvalueof{/pgf/decoration/mark info/sequence number}) at (1,0pt);
                    \coordinate (tangent orthogonal unit vector-\pgfkeysvalueof{/pgf/decoration/mark info/sequence number}) at (0pt,1);
                }
        },
        postaction=decorate
    },
    use tangent/.style={
        shift=(tangent point-#1),
        x=(tangent unit vector-#1),
        y=(tangent orthogonal unit vector-#1)
    },
    use tangent/.default=1
  }
\newcommand{\zoom}[1]{
  \begin{tikzpicture}[scale=#1]
  \pgfmathsetmacro{\al}{20}
  \draw[tangent={\al/360}] (0,0) circle (3);
  \fill (\al:3) circle (0.1/#1) coordinate (P);
  \draw[use tangent] (-2,0) -- (2,0);
  \clip (P) circle ({6/#1});
  \pgfresetboundingbox
  \end{tikzpicture}
  }

\begin{document}

Zoomlevel 1: 
\begin{center}
\zoom{1}
\end{center}

Zoomlevel 2:
\begin{center}
\zoom{2}
\end{center}

Zoomlevel 5:
\begin{center}
\zoom{5}
\end{center}
\end{document}

输出:

在此处输入图片描述

相关内容