我正在寻找
我正在使用 TikZ 创建用于练习手写的备忘单。我想使用正弦波作为练习手写的图案,所以我想在同一页中显示水平和垂直正弦波。在我创建的备忘单中,我想绘制一组水平正弦波,它们从纸张的一端延伸到另一端,并且非常接近。在该组下方,我想绘制一组垂直正弦波。我使用 Inkscape 创建了以下图形来显示我正在寻找的内容。
我尝试过的方法
我知道如何使用 TikZ 绘制水平正弦波。请参阅下面的最小工作示例。
\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw[opacity=0.2] (0,0) grid (10,2);
\draw[red] (0,1) sin (1, 2);
\draw[blue] (1,2) cos (2, 1);
\draw[red] (2,1) sin (3, 0);
\draw[blue] (3,0) cos (4, 1);
\draw[red] (4,1) sin (5, 2);
\draw[blue] (5,2) cos (6, 1);
\draw[red] (6,1) sin (7, 0);
\draw[blue] (7,0) cos (8, 1);
\draw[red] (8,1) sin (9, 2);
\draw[blue] (9,2) cos (10,1);
\end{tikzpicture}
\end{document}
为了创建垂直正弦波,我尝试使用sin
和cos
并逐个指定坐标。但是,考虑到sin
和cos
函数的性质,这看起来不像第一个图形那么平滑。
%% This file is intended to be compiled by executing the following
%% commands:
%% $ pdflatex main
\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw[opacity=0.2] (0,2) grid (10,-10);
% Horizontal sine wave
\draw[red] (0,1) sin (1, 2);
\draw[blue] (1,2) cos (2, 1);
\draw[red] (2,1) sin (3, 0);
\draw[blue] (3,0) cos (4, 1);
\draw[red] (4,1) sin (5, 2);
\draw[blue] (5,2) cos (6, 1);
\draw[red] (6,1) sin (7, 0);
\draw[blue] (7,0) cos (8, 1);
\draw[red] (8,1) sin (9, 2);
\draw[blue] (9,2) cos (10,1);
% My attempt to draw a vertical sine wave (the result is not a
% vertical sine wave)
\draw[red] (1,-0) cos (2,-1);
\draw[blue] (2,-1) sin (1,-2);
\draw[red] (1,-2) cos (0,-3);
\draw[blue] (0,-3) sin (1,-4);
\draw[red] (1,-4) cos (2,-5);
\draw[blue] (2,-5) sin (1,-6);
\draw[red] (1,-6) cos (0,-7);
\draw[blue] (0,-7) sin (1,-8);
\draw[red] (1,-8) cos (2,-9);
\draw[blue] (2,-9) sin (1,-10);
\end{tikzpicture}
\end{document}
问题
如何在相同环境下在水平正弦波下方显示垂直正弦波tikzpicture
?
答案不需要是上面显示的第一个图形的代码,它是我使用 Inkscape 创建的。在相同环境中,水平正弦波下方的垂直正弦波tikzpicture
就足够了。
答案1
您是否考虑过旋转水平正弦波?
\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw[opacity=0.2] (0,2) grid (10,-10);
% Horizontal sine wave
\draw[red] (0,1) sin (1, 2);
\draw[blue] (1,2) cos (2, 1);
\draw[red] (2,1) sin (3, 0);
\draw[blue] (3,0) cos (4, 1);
\draw[red] (4,1) sin (5, 2);
\draw[blue] (5,2) cos (6, 1);
\draw[red] (6,1) sin (7, 0);
\draw[blue] (7,0) cos (8, 1);
\draw[red] (8,1) sin (9, 2);
\draw[blue] (9,2) cos (10,1);
% Vertical sine wave; draw horizontal & rotate
\draw[red, rotate around={-90:(1.5,-1)}] (0,-1) sin (1, -2);
\draw[blue, rotate around={-90:(1.5,-1)}] (1,-2) cos (2, -1);
\draw[red, rotate around={-90:(1.5,-1)}] (2,-1) sin (3, -0);
\draw[blue, rotate around={-90:(1.5,-1)}] (3,-0) cos (4, -1);
\draw[red, rotate around={-90:(1.5,-1)}] (4,-1) sin (5, -2);
\draw[blue, rotate around={-90:(1.5,-1)}] (5,-2) cos (6, -1);
\draw[red, rotate around={-90:(1.5,-1)}] (6,-1) sin (7, -0);
\draw[blue, rotate around={-90:(1.5,-1)}] (7,-0) cos (8, -1);
\draw[red, rotate around={-90:(1.5,-1)}] (8,-1) sin (9, -2);
\draw[blue, rotate around={-90:(1.5,-1)}] (9,-2) cos (10,-1);
\end{tikzpicture}
\end{document}
您也可以使用函数来捕获它们。
\begin{document}
\begin{tikzpicture}
\draw[opacity=0.2] (0,2) grid (10,-10);
\draw[domain=0:10, smooth, samples=100, thick, red] plot (\x, {sin(pi/2
* \x r) + 1});
\draw[domain=0:10, smooth, samples=100, thick, blue] plot ({sin(pi/2 * \x r) + 1}, -\x);
\end{tikzpicture}
\end{document}
输出:
更进一步说,如果您想制作许多这样的图,我建议您创建一个函数,该函数接受起点和水平/垂直长度的输入,从而沿着它创建正弦波。