在 TikZ 图片中缩放、旋转和变换椭圆

在 TikZ 图片中缩放、旋转和变换椭圆

我想画一些椭圆,然后在不改变其面积的情况下变换椭圆。

我希望能够根据以下两个方程来变换椭圆;

第一次转型:

∆y = 常数 * x 且 ∆x = 0

其中 x 是坐标的水平位置,∆y 是垂直 (y) 位置的变化

第二次转型

∆x = 常数 * y 且 ∆y = 0

其中 y 是坐标的垂直位置,∆x 是水平 (x) 位置的变化

在第一张图片中,我从一个水平椭圆开始(见附图),其中包含一些红线和蓝线,也需要转换。

此椭圆使用第一个变换进行变换(已成功完成...)

我无法使第二个变换起作用(见图 3...)我使用了旋转,但这是不正确的,因为它不满足方程 2,我不知道如何使用范围来实现这一点...

第四张图像再次是第一次转换,但这不再起作用了......

在此处输入图片描述

有人可以帮忙吗?

谢谢。

这是我的乳胶代码

\documentclass[11pt]{article}
\usepackage{tikz} 
\usepackage{verbatim}
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}
\setlength\PreviewBorder{5pt}%
\usetikzlibrary{calc}


\begin{document}



\newcommand{\addphasespace}[5]{
\begin{scope}[xshift=#1]
\draw (-1.5,-1.5) rectangle (1.5,1.5);
\draw (-1.5,0) -- (1.5,0);
\draw (0,-1.5) -- (0,1.5);
\node[inner sep=1pt,font=\large] at (0,-1.75) {$x$};
\node[inner sep=1pt,font=\large] at (1.75,0) {$y$};
\node[inner sep=1pt,font=\large] at (0,1.9) {#5};
\begin{scope}[#4]
\fill[black!20,yshift=0cm] (0,0) circle (#2 and #3);
\draw[yshift=0cm,red] (-#2,0) -- (#2,0);
\draw[yshift=0cm,blue] (0,-#3) -- (0,#3);
\draw[yshift=0cm,blue] (0.1,-0.195) -- (0.1,0.195);
\draw[yshift=0cm,blue] (-0.1,-0.195) -- (-0.1,0.195);
\draw[yshift=0cm,blue] (0.2,-0.19) -- (0.2,0.19);
\draw[yshift=0cm,blue] (-0.2,-0.19) -- (-0.2,0.19);
\draw[yshift=0cm,blue] (0.3,-0.18) -- (0.3,0.18);
\draw[yshift=0cm,blue] (-0.3,-0.18) -- (-0.3,0.18);
\draw[yshift=0cm,blue] (0.4,-0.17) -- (0.4,0.17);
\draw[yshift=0cm,blue] (-0.4,-0.17) -- (-0.4,0.17);
\draw[yshift=0cm,blue] (0.5,-0.158) -- (0.5,0.158);
\draw[yshift=0cm,blue] (-0.5,-0.158) -- (-0.5,0.158);
\draw[yshift=0cm,blue] (0.6,-0.135) -- (0.6,0.135);
\draw[yshift=0cm,blue] (-0.6,-0.135) -- (-0.6,0.135);
\draw[yshift=0cm,blue] (0.7,-0.1) -- (0.7,0.1);
\draw[yshift=0cm,blue] (-0.7,-0.1) -- (-0.7,0.1);
\draw[yshift=0cm] (0,0) circle (#2 and #3);
\end{scope}
\end{scope}
}

%%%%%%%%%%%%%%%


\begin{figure}
\begin{tikzpicture}
\draw[help lines] (-3,-3) grid (15,3);

% area ellipse  = pi*0.8*0.2 = 0.5026

%Plot1
\addphasespace{0cm}{0.8}{0.2}{}{1}

%Plot2
\draw[->] (4.8,0) -- (4.8,-0.85);
\draw[->] (3.2,0) -- (3.2,0.85);
\addphasespace{4cm}{0.8}{0.2}{opacity = 0.3}{2}
\addphasespace{4cm}{0.8}{0.2}{x={(1,-1.3)}}{2}


%%Plot3
\draw[->] (7.2,1.05) -- (7.9,1.05);
\draw[->] (8.8,-1.05) -- (8.1,-1.05);
\addphasespace{8cm}{0.8}{0.2}{opacity = 0.3,x={(1,-1.3)}}{3}
\addphasespace{8cm}{0.8}{0.2}{x={(1,-1.3)},rotate=-37.57}{3}


%%Plot3
\draw[->]  (12.82,1.05) -- (12.82,0.1);
\draw[->]  (11.18,-1.05) -- (11.18,0.1);
\addphasespace{12cm}{0.8}{0.2}{opacity = 0.3 ,x={(1,-1.3)},rotate=-75.14}{4}
\addphasespace{12cm}{0.8}{0.2}{x={(1,-1.3)},rotate=-127.57,x={(1,-1.5)}}{4}





\end{tikzpicture}
\end{figure}

\end{document}

答案1

您说第二次变换与描述不符,这是对的,但严格来说,第一次变换已经是这样的了。(笔记:在之前的版本中,我声称这些变换是非线性的,但事实并非如此,但我实施的变换是遵循您的规定的。它们与以下内容一致,当然,只是以下内容更简单。)

在此处输入图片描述

\documentclass[11pt]{article}
\usepackage[top=0.7in,bottom=0.7in,left=0.5in,right=0.5in]{geometry}
\usepackage{tikz} 
\usepackage{mathtools}
% \usepackage[active,tightpage]{preview}
% \PreviewEnvironment{tikzpicture}
% \setlength\PreviewBorder{5pt}%
\usetikzlibrary{calc}
\newcommand{\MyConst}{-0.8}




\newcommand{\addphasespace}[2]{
\begin{scope}[xshift=#1]
\draw (-1.5,-1.5) rectangle (1.5,1.5);
\draw (-1.5,0) -- (1.5,0);
\draw (0,-1.5) -- (0,1.5);
\node[inner sep=1pt,font=\large] at (0,-1.75) {$x$};
\node[inner sep=1pt,font=\large] at (1.75,0) {$y$};
\node[inner sep=1pt,font=\large] at (0,1.9) {#2};
\end{scope}
}

\newcommand{\drawellipse}[4][]{
\begin{scope}[#4]
\fill[black!20,yshift=0cm] (0,0) circle (#2 and #3);
\draw[yshift=0cm,red] (-#2,0) -- (#2,0);
\foreach \X in {0,0.1,...,#2}
{
\pgfmathsetmacro{\Y}{#3*sin(acos(\X/#2))}
\draw[yshift=0cm,blue] (\X,-\Y) -- (\X,\Y);
\draw[yshift=0cm,blue] (-\X,-\Y) -- (-\X,\Y);
}
\draw[yshift=0cm] (0,0) circle (#2 and #3);
\end{scope}
}

\newcommand{\trafoone}[1]{
\pgftransformcm{1}{#1}{0}{1}{\pgfpoint{0pt}{0pt}}
}
\newcommand{\trafotwo}[1]{
\pgftransformcm{1}{0}{#1}{1}{\pgfpoint{0pt}{0pt}}
}
\newcommand{\trafooneaftertwo}[2]{
\pgftransformcm{1}{#1}{#2}{1+#1*#2}{\pgfpoint{0pt}{0pt}}
}
\newcommand{\trafotwoafterone}[2]{
\pgftransformcm{1+#1*#2}{#2}{#1}{1}{\pgfpoint{0pt}{0pt}}
}

%%%%%%%%%%%%%%%

\begin{document}


You are looking at transformations of the type
\[
\begin{pmatrix} x\\ y\end{pmatrix}\xmapsto{~f_1~}
\begin{pmatrix} x\\ y+c_1\, x\end{pmatrix}
\quad\text{and}\quad
\begin{pmatrix} x\\ y\end{pmatrix}\xmapsto{~f_2~}
\begin{pmatrix} x+c_2\,y\\ y\end{pmatrix}\;,
\]
which can be written in matrix form as
\[
\begin{pmatrix} x\\ y\end{pmatrix}\xmapsto{~f_1~}
\underbrace{\begin{pmatrix} 1 & 0\\ c_1 & 1\end{pmatrix}}_{=A_1}\cdot
\begin{pmatrix} x\\ y\end{pmatrix}
\quad\text{and}\quad
\begin{pmatrix} x\\ y\end{pmatrix}\xmapsto{~f_2~}
\underbrace{\begin{pmatrix} 1 & c_2\\ 0 & 1\end{pmatrix}}_{=A_2}\cdot
\begin{pmatrix} x\\ y\end{pmatrix}\;.
\]
These transformations do not commute,
\[
 A_1\cdot A_2=
 \begin{pmatrix} 1 & c_2\\ c_1 & 1+c_1\,c_2\end{pmatrix}
 \ne
 \begin{pmatrix} 1+c_1\,c_2 & c_2\\ c_1 & 1\end{pmatrix}=A_2\cdot A_1\;.
\]
You can implement these transformations with \verb|\pgftransformcm|, which is
equivalent to \texttt{[cm=\dots]} in a scope. This version comes with four commands
\[ \verb|\trafoone{#1}|\;,\quad\verb|\trafotwo{#1}|\;,\quad
\verb|\trafooneaftertwo{#1}{#2}|\quad\text{and}\quad \verb|\trafotwoafterone{#1}{#2}|\;,
\] 
which correspond to the transformation matrices
\[A_1\;,\quad A_2\;,\quad A_1\cdot A_2 \quad\text{and}\quad
A_2\cdot A_1\;, %@DavidCarlisle @barbarabeeton please don't kill me for the spaces ;-)
\]
respectively. See Figure \ref{fig:trafos} for some examples, which are chosen to resemble
your screenshot.
\begin{figure}
% @egreg please don't kill me for using \centerline ;-)
\centering
\begin{tikzpicture}
\draw[help lines] (-3,-3) grid (15,3);
% area ellipse  = pi*0.8*0.2 = 0.5026
%Plot1
\addphasespace{0cm}{1}
\drawellipse{0.8}{0.2}{}
%Plot2
\addphasespace{4cm}{2}
\begin{scope}[xshift=4cm]
\drawellipse{0.8}{0.2}{opacity = 0.3}
\begin{scope}
\trafoone{\MyConst}
\drawellipse{0.8}{0.2}{}
\end{scope}
\end{scope}
%%Plot3
\addphasespace{8cm}{3}
\begin{scope}[xshift=8cm]
\trafoone{\MyConst}
\drawellipse{0.8}{0.2}{opacity = 0.3}
\begin{scope}
\trafotwoafterone{\MyConst}{-\MyConst}
\drawellipse{0.8}{0.2}{};
\end{scope}
\end{scope}
%%Plot4
\addphasespace{12cm}{4}
\begin{scope}[xshift=12cm]
\trafotwo{\MyConst}
\drawellipse{0.8}{0.2}{opacity = 0.3}
\begin{scope}
\trafooneaftertwo{-\MyConst}{\MyConst}
\drawellipse{0.8}{0.2}{};
\end{scope}
\end{scope}
\end{tikzpicture}
\caption{$f_1$, $f_2$, $f_2\circ f_1$ and $f_1\circ f_2$.}
\label{fig:trafos}
\end{figure}
\end{document}

还有动画,就像@J Leon V. 的回答一样。

\documentclass[tikz,border=3.14]{standalone}


\newcommand{\addphasespace}[2]{
\begin{scope}[xshift=#1]
\draw (-1.5,-1.5) rectangle (1.5,1.5);
\draw (-1.5,0) -- (1.5,0);
\draw (0,-1.5) -- (0,1.5);
\node[inner sep=1pt,font=\large] at (0,-1.75) {$x$};
\node[inner sep=1pt,font=\large] at (1.75,0) {$y$};
\node[inner sep=1pt,font=\large] at (0,1.9) {#2};
\end{scope}
}

\newcommand{\drawellipse}[4][]{
\begin{scope}[#4]
\fill[black!20,yshift=0cm] (0,0) circle (#2 and #3);
\draw[yshift=0cm,red] (-#2,0) -- (#2,0);
\foreach \X in {0,0.1,...,#2}
{
\pgfmathsetmacro{\Y}{#3*sin(acos(\X/#2))}
\draw[yshift=0cm,blue] (\X,-\Y) -- (\X,\Y);
\draw[yshift=0cm,blue] (-\X,-\Y) -- (-\X,\Y);
}
\draw[yshift=0cm] (0,0) circle (#2 and #3);
\end{scope}
}

%%%%%%%%%%%%%%%
\begin{document}
\foreach \MyConst [count=\Z] in {0,0.1,...,2}
{\begin{tikzpicture}
\draw[help lines] (-3,-3) grid (15,3);
% area ellipse  = pi*0.8*0.2 = 0.5026
%Plot1
\addphasespace{0cm}{1}
\drawellipse{0.8}{0.2}{}
%Plot2
\addphasespace{4cm}{2}
\begin{scope}[xshift=4cm]
\drawellipse{0.8}{0.2}{opacity = 0.3}
\begin{scope}
\pgftransformcm{1}{\MyConst}{0}{1}{\pgfpoint{0pt}{0pt}}
\drawellipse{0.8}{0.2}{}
\coordinate (l1) at (-0.8,0);
\coordinate (r1) at (0.8,0);
\end{scope}
\ifnum\Z=1
\else
\draw[-latex] (-0.8,0) -- (l1);
\draw[-latex] (0.8,0) -- (r1);
\fi
\end{scope}
%%Plot3
\addphasespace{8cm}{3}
\begin{scope}[xshift=8cm]
\drawellipse{0.8}{0.2}{opacity = 0.3}
\begin{scope}
\pgftransformcm{1}{0}{\MyConst}{1}{\pgfpoint{0pt}{0pt}}
\drawellipse{0.8}{0.2}{};
\coordinate (l2) at (-0.8,0);
\coordinate (r2) at (0.8,0);
\end{scope}
\end{scope}
%%Plot4
\addphasespace{12cm}{4}
\begin{scope}[xshift=12cm]
\drawellipse{0.8}{0.2}{opacity = 0.3}
\begin{scope}
\pgftransformcm{1}{\MyConst}{\MyConst}{{1+\MyConst*\MyConst}}{\pgfpoint{0pt}{0pt}}
\drawellipse{0.8}{0.2}{};
\coordinate (l3) at (-0.8,0);
\coordinate (r3) at (0.8,0);
\end{scope}
\ifnum\Z=1
\else
\draw[-latex] (-0.8,0) -- (l3);
\draw[-latex] (0.8,0) -- (r3);
\fi
\end{scope}
\end{tikzpicture}}
\end{document}

在此处输入图片描述

正如您所见,变换确实保留了该区域,这是应该的(因为它们有行列式 1)。

答案2

虽然对我来说不是很清楚,但根据您放置的箭头进行更改和缩放的一种方法是使用选项/tikz/cm={<a>,<b>,<c>,<d>,<coordinate>},第一个图形只是旋转形状而不改变面积,以下是根据箭头缩放的,如果这是您想要的,请告诉我,您可以尝试使用代码。

更新:对区域中的任意变化进行可视化的修改,模拟其保存恒定区域。

%Plot1
\addphasespace{0cm}{0.8}{0.2}{rotate=360/20*\X}{1}
%Plot2
\draw[->] (4.8,0) -- ++(0,-0.85);
\draw[->] (3.2,0) -- ++(0,0.85);
\addphasespace{4cm}{0.8}{0.2}{opacity = 0.3}{2}
\addphasespace{4cm}{0.8}{0.2}{cm={1,-1*\X/20,0.5*\X/20,1-0.5*\X/20,(0,0)}}{2}
%Plot3
\draw[->] (7.2,0.8) -- ++(0.85,0);
\draw[->] (8.8,-0.8) -- ++(-0.85,0);
\addphasespace{8cm}{0.8}{0.2}{opacity = 0.3,cm={1,-1,0.5,0.5,(0,0)}}{3}
\addphasespace{8cm}{0.8}{0.2}{cm={1-1*\X/20,-1,0.5+0.5*\X/20,0.5-0.5*\X/20,(0,0)}}{3}
%Plot4
\draw[->]  (12.82,0.8) -- ++(0,-0.85);
\draw[->]  (11.18,-0.8) -- ++(0,0.85);
\addphasespace{12cm}{0.8}{0.2}{opacity = 0.3,cm={1,1,-0.5,0.5,(0,0)}}{4}
\addphasespace{12cm}{0.8}{0.2}{cm={1,1-1*\X/20,-0.5+0.5*\X/20,0.5+0.5*\X/20,(0,0)}}{4}

更新结果: 在此处输入图片描述

结果: 在此处输入图片描述

梅威瑟:

% arara: pdflatex: {synctex: yes, action: nonstopmode}
% arara: animate: {density: 150, delay: 8, other: -background white -alpha remove}
% arara: showanimate

\documentclass[tikz,border=1pt]{standalone}
\usepackage{tikz} 
\usetikzlibrary{calc}
\begin{document}
    \foreach \X in {1,...,20}
    {\begin{tikzpicture}
        \newcommand{\addphasespace}[5]{
        \begin{scope}[xshift=#1]
        \draw (-1.5,-1.5) rectangle (1.5,1.5);
        \draw (-1.5,0) -- (1.5,0);
        \draw (0,-1.5) -- (0,1.5);
        \node[inner sep=1pt,font=\large] at (0,-1.75) {$x$};
        \node[inner sep=1pt,font=\large] at (1.75,0) {$y$};
        \node[inner sep=1pt,font=\large] at (0,1.9) {#5};
        \begin{scope}[#4]
        \fill[black!20] (0,0) circle (#2 and #3);
        \draw[red] (-#2,0) -- (#2,0);
        \draw[blue] (0,-#3) -- (0,#3);
        \draw[blue] (0.1,-0.195) -- (0.1,0.195);
        \draw[blue] (-0.1,-0.195) -- (-0.1,0.195);
        \draw[blue] (0.2,-0.19) -- (0.2,0.19);
        \draw[blue] (-0.2,-0.19) -- (-0.2,0.19);
        \draw[blue] (0.3,-0.18) -- (0.3,0.18);
        \draw[blue] (-0.3,-0.18) -- (-0.3,0.18);
        \draw[blue] (0.4,-0.17) -- (0.4,0.17);
        \draw[blue] (-0.4,-0.17) -- (-0.4,0.17);
        \draw[blue] (0.5,-0.158) -- (0.5,0.158);
        \draw[blue] (-0.5,-0.158) -- (-0.5,0.158);
        \draw[blue] (0.6,-0.135) -- (0.6,0.135);
        \draw[blue] (-0.6,-0.135) -- (-0.6,0.135);
        \draw[blue] (0.7,-0.1) -- (0.7,0.1);
        \draw[blue] (-0.7,-0.1) -- (-0.7,0.1);
        \draw(0,0) circle (#2 and #3);
        \end{scope}
        \end{scope}
    }
    %%%%%%%%%%%%%%%
    \draw[help lines] (-3,-3) grid (15,3);
    % area ellipse  = pi*0.8*0.2 = 0.5026
    %Plot1
    \addphasespace{0cm}{0.8}{0.2}{rotate=360/20*\X}{1}
    %Plot2
    %Plot2
    \draw[->] (4.8,0) -- ++(0,-0.85);
    \draw[->] (3.2,0) -- ++(0,0.85);
    \addphasespace{4cm}{0.8}{0.2}{opacity = 0.3}{2}
    \addphasespace{4cm}{0.8}{0.2}{cm={1,-1*\X/20,1*\X/20,1,(0,0)}}{2}


    %%Plot3
    \draw[->] (7.2,0.8) -- ++(0.85,0);
    \draw[->] (8.8,-0.8) -- ++(-0.85,0);
    \addphasespace{8cm}{0.8}{0.2}{opacity = 0.3,cm={1,-1,1,1,(0,0)}}{3}
    \addphasespace{8cm}{0.8}{0.2}{cm={1-1*\X/20,-1,1,1-1*\X/20,(0,0)}}{3}


    %%Plot4
    \draw[->]  (12.82,0.8) -- ++(0,-0.85);
    \draw[->]  (11.18,-0.8) -- ++(0,0.85);
    \addphasespace{12cm}{0.8}{0.2}{opacity = 0.3,cm={1,1,-1,1,(0,0)}}{4}
    \addphasespace{12cm}{0.8}{0.2}{cm={1,1-1*\X/20,-1+\X/20,1,(0,0)}}{4}
    \end{tikzpicture}}
\end{document}

PSD:对于动画,我使用 imagemagic,它可以将 pdf 文件转换为 gif 文档。

相关内容