![如何用 TikZ 绘制曲柄滑块机构的曲线?](https://linux22.com/image/435182/%E5%A6%82%E4%BD%95%E7%94%A8%20TikZ%20%E7%BB%98%E5%88%B6%E6%9B%B2%E6%9F%84%E6%BB%91%E5%9D%97%E6%9C%BA%E6%9E%84%E7%9A%84%E6%9B%B2%E7%BA%BF%EF%BC%9F.png)
我不知道如何绘制这么复杂的曲线,即使我得到了它的参数方程和隐式方程。
曲线的参数方程
\begin{cases}
\begin{split}
x&=r\sin\left(t\right)+\frac{L}{R}\sqrt{R^2-r^2\cos^2\left(t\right)}\\
y&=\left(1-\frac{L}{R}\right)r\cos\left(t\right)
\end{split}
\end{cases}
曲线隐式方程:
\[x^4-2\left(L^2+r^2-\frac{\left(L^2+R^2\right)y^2}{\left(L-R\right)^2}\right)x^2+\left(L^2-r^2-\frac{\left(L^2-R^2\right)y^2}{\left(L-R\right)^2}\right)^2=0\]
O-orange:r=1.5;
orange-red:L=2.5;
orange-blake:R=6;
答案1
你可以plot
直接得到参数方程。比如
\def\r{1.5}
\def\L{2.5}
\def\R{6}
\draw plot[domain=0:360] ({\r*sin(\x)+\L/\R*sqrt(\R*\R-\r*\r*cos(\x)*cos(\x))},{(1-\L/\R)*\r*cos(\x)});
将绘制曲线。
一个完整的例子可能是:
\documentclass[border=2mm]{standalone}
\usepackage {tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}[line cap=round,line join=round]
% dimensions
\def\r{1.5}
\def\L{2.5}
\def\R{6}
\def\a{60} % orange line angle
\pgfmathsetmacro\b{asin(\r/\R*sin(\a))} % blue line angle
% axes and grid
\draw[gray,step=0.5] (-2.25,-2.25) grid (8.75,2.25);
\draw[step=2] (-2.25,-2.25) grid (8.75,2.25);
\draw[thick] (-2.25,0) -- (8.75,0);
\draw[thick] (0,-2.25) -- (0,2.25);
\foreach\i in {\R-\r,\R+\r}
{%
\draw[thick] (\i-0.05,-0.05) --++ (0.1,0.1);
\draw[thick] (\i+0.05,-0.05) --++ (-0.1,0.1);
}
% curve
\draw[red,dashed] plot[domain=0:360,samples=100] ({\r*sin(\x)+\L/\R*sqrt(\R*\R-\r*\r*cos(\x)*cos(\x))},{(1-\L/\R)*\r*cos(\x)});
% segments
\coordinate (O) at (0,0);
\coordinate (A) at (\a:\r);
\coordinate (C) at ($(A)+(-\b:\R)$);
\coordinate (B) at ($(A)!{\L/\R}!(C)$);
\draw[thick,orange] (O) -- (A);
\draw[thick,blue] (A) -- (C);
\draw[orange,thick,fill=white] (A) circle (1pt);
\draw[orange,thick,fill=white] (B) circle (1pt);
\draw[thick,fill=white] (C) circle (1pt);
\end{tikzpicture}
\end{document}
并且,如果改变角度值\a
:
\documentclass {beamer}
\usepackage {tikz}
\usetikzlibrary {calc}
\setbeamertemplate{navigation symbols}{}
\begin{document}
\begin{frame}
\begin{figure}\centering
\begin{tikzpicture}[line cap=round,line join=round]
% dimensions
\def\r{1.5}
\def\L{2.5}
\def\R{6}
% axes and grid
\draw[gray,step=0.5] (-2.25,-2.25) grid (8.75,2.25);
\draw[step=2] (-2.25,-2.25) grid (8.75,2.25);
\draw[thick] (-2.25,0) -- (8.75,0);
\draw[thick] (0,-2.25) -- (0,2.25);
\foreach\i in {\R-\r,\R+\r}
{%
\draw[thick] (\i-0.05,-0.05) --++ (0.1,0.1);
\draw[thick] (\i+0.05,-0.05) --++ (-0.1,0.1);
}
% curve
\draw[red,dashed] plot[domain=0:360,samples=100] ({\r*sin(\x)+\L/\R*sqrt(\R*\R-\r*\r*cos(\x)*cos(\x))},{(1-\L/\R)*\r*cos(\x)});
% segments
\coordinate (O) at (0,0);
\foreach\i in {1,...,36}
{%
\only<\i>
{%
\pgfmathsetmacro\a{10-10*\i} % orange line angle
\pgfmathsetmacro\b{asin(\r/\R*sin(\a))} % blue line angle
\coordinate (A) at (\a:\r);
\coordinate (C) at ($(A)+(-\b:\R)$);
\coordinate (B) at ($(A)!{\L/\R}!(C)$);
\draw[thick,orange] (O) -- (A);
\draw[thick,blue] (A) -- (C);
\draw[orange,thick,fill=white] (A) circle (1pt);
\draw[orange,thick,fill=white] (B) circle (1pt);
\draw [thick,fill=white] (C) circle (1pt);
}
}
\end{tikzpicture}
\end{figure}
\end{frame}
\end{document}