我尝试改编缩放代码https://tex.stackexchange.com/a/457705/21557变成椭圆,但如果我选择的缩放系数足够高,切线位置就会明显不匹配:
我怎样才能做到这一点?代码如下:
\documentclass[tikz,border=5mm]{standalone}
\usetikzlibrary{calc,decorations.markings,positioning,angles}
\usepackage{fp}
\usepgflibrary{fixedpointarithmetic}
\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
}
\begin{document}
\begin{tikzpicture}[
% Style for the spy nodes and the connection line
spy/.style={%
draw,orange,
line width=1pt,
circle,inner sep=0pt,
},
]
% Parameters
%% size of the spy-in nodes
\def\spyviewersize{4.25cm}
%% (line width of the spy nodes) / 2
%% we need this for clipping later
\def\spyonclipreduce{0.5pt}
%% first zoom
%%% factor
\def\spyfactorI{20}
%%% spy in point
\coordinate (spy-in 1) at (8,0);
%%% spy on point
\pgfmathsetmacro{\a}{2}
\pgfmathsetmacro{\b}{1.5}
\pgfmathsetmacro{\al}{30}
\coordinate (spy-on 1) at ({\a*cos(\al)},{\b*sin(\al)});% sould be on the curve
%% the graph/picture
\def\pik{
% \draw[tangent={\al/360}] (0,0) circle (3);
\draw[tangent={\al/360}] plot[domain=0:360,samples=800] ({\a*cos(\x)},{\b*sin(\x)});
\draw[use tangent,green,thick] (-2,0) -- (2,0) coordinate (XA);
\draw[use tangent,red] (-2,0.3) -- (2,-0.3) coordinate (XB);
\node[fill,circle,inner sep=0pt,minimum size=2pt] (P) at
({\a*cos(\al)},{\b*sin(\al)}) {};
\node[right] at (P) {$P$};
}
% draw the original picture
\pik
% first zoom
%% spy on node
\node[spy,minimum size={\spyviewersize/\spyfactorI}] (spy-on node 1) at (spy-on 1) {};
%% spy in node
\node[spy,minimum size=\spyviewersize] (spy-in node 1) at (spy-in 1) {};
\begin{scope}
\clip (spy-in 1) circle (0.5*\spyviewersize-\spyonclipreduce);
\pgfmathsetmacro\sI{1/\spyfactorI}
\begin{scope}[
shift={($\sI*(spy-in 1)-\sI*(spy-on 1)$)},
scale around={\spyfactorI:(spy-on 1)},
]
\pik
%%
\pic[draw,angle radius=50,fill=blue!50,pic text=$\varphi$]{angle=XB--P--XA};
%% How to interpret the measure 50 for the angle radius
\end{scope}
\end{scope}
%% connect the nodes
\draw [spy] (spy-on node 1) -- (spy-in node 1);
\end{tikzpicture}
\end{document}
答案1
您使用了一种非常好的切线样式,它实际上可以为您计算相关点,它被称为tangent point-1
。为什么不直接使用它呢?
\documentclass[tikz,border=5mm]{standalone}
\usetikzlibrary{calc,decorations.markings,positioning,angles}
\usepackage{fp}
\usepgflibrary{fixedpointarithmetic}
\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
}
\begin{document}
\begin{tikzpicture}[
% Style for the spy nodes and the connection line
spy/.style={%
draw,orange,
line width=1pt,
circle,inner sep=0pt,
},
]
% Parameters
%% size of the spy-in nodes
\def\spyviewersize{4.25cm}
%% (line width of the spy nodes) / 2
%% we need this for clipping later
\def\spyonclipreduce{0.5pt}
%% first zoom
%%% factor
\def\spyfactorI{20}
%%% spy in point
\coordinate (spy-in 1) at (8,0);
%%% spy on point
\pgfmathsetmacro{\a}{2}
\pgfmathsetmacro{\b}{1.5}
\pgfmathsetmacro{\al}{30}
% \coordinate (spy-on 1) at ({\a*cos(\al)},{\b*sin(\al)});% sould be on the curve
%% the graph/picture
\def\pik{
% \draw[tangent={\al/360}] (0,0) circle (3);
\draw[tangent={\al/360}] plot[domain=0:360,samples=800] ({\a*cos(\x)},{\b*sin(\x)});
\draw[use tangent,green,thick] (-2,0) -- (2,0) coordinate (XA);
\draw[use tangent,red] (-2,0.3) -- (2,-0.3) coordinate (XB);
\node[fill,circle,inner sep=0pt,minimum size=2pt] (P) at
(tangent point-1) {};
\node[right] at (P) {$P$};
}
% draw the original picture
\pik
\coordinate (spy-on 1) at (tangent point-1);% sould be on the curve
% first zoom
%% spy on node
\node[spy,minimum size={\spyviewersize/\spyfactorI}] (spy-on node 1) at (spy-on 1) {};
%% spy in node
\node[spy,minimum size=\spyviewersize] (spy-in node 1) at (spy-in 1) {};
\begin{scope}
\clip (spy-in 1) circle (0.5*\spyviewersize-\spyonclipreduce);
\pgfmathsetmacro\sI{1/\spyfactorI}
\begin{scope}[
shift={($\sI*(spy-in 1)-\sI*(spy-on 1)$)},
scale around={\spyfactorI:(spy-on 1)},
]
\pik
%%
\pic[draw,angle radius=50,fill=blue!50]{%
angle=XB--tangent point-1--XA};
\coordinate (aux) at (barycentric cs:XA=1,XB=1,tangent point-1=1);
\node[right=4mm of aux] (phi){$\varphi$};
\draw[-latex] (phi) to[bend right](aux);
%% How to interpret the measure 50 for the angle radius
\end{scope}
\end{scope}
%% connect the nodes
\draw [spy] (spy-on node 1) -- (spy-in node 1);
\end{tikzpicture}
\end{document}