我需要使用 Tikz 绘制几个互锁的圆环,如图所示。
我在网上查看了一些示例,但只找到了使用 Gnuplot 的说明,没有关于 Tikz 的任何信息。如果有人能提供帮助,我将不胜感激。
答案1
你可以像这样绘制 4 个半圆环面:
\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.12}
\pgfplotsset{
torus/.style 2 args={
surf,
color=#1!50,faceted color=#1,
samples=17,
z buffer=sort,
domain=0:360, y domain=#2:#2+180
}
}
\def\m{sin(x)}
\def\n{(2+cos(x))*sin(y)}
\def\p{(2+cos(x))*cos(y)}
\begin{document}
\begin{tikzpicture}
\begin{axis}[hide axis,axis equal,scale=3,view={20}{20}]
\addplot3[torus={blue}{0}] (\m,\n,\p);
\addplot3[torus={red}{0}] (\p,\n-2,\m);
\addplot3[torus={blue}{180}] (\m,\n,\p);
\addplot3[torus={red}{180}] (\p,\n-2,\m);
\end{axis}
\end{tikzpicture}
\end{document}
答案2
运行xelatex
:
\documentclass[pstricks]{standalone}
\usepackage{pst-solides3d}
\begin{document}
\psset{Decran=50,viewpoint=20 80 30,lightsrc=viewpoint,action=none}
\begin{pspicture}[solidmemory](-4,-3)(3,3)
\psSolid[r1=2.5,r0=1.5,object=tore,ngrid=18 36,fillcolor=green!30,name=tA]
\psSolid[r1=2.5,r0=1.5,object=tore,ngrid=18 36,fillcolor=blue!30,RotX=90,name=tB](2,0,0)
\psSolid[object=fusion,base=tA tB,action=draw**]
\end{pspicture}
\end{document}
答案3
有点晚了,但是这里有一个使用的解决方案asymptote
。
/* Used for rendering parameterized 3D objects. */
import graph3;
/* PDF works best with LaTeX, output this. Also set the render factor high. */
import settings;
settings.outformat = "pdf";
settings.render = 8;
/* Size of the image. For 3D objects it seems best to have this set to a *
* power of 2, otherwise weird vertical or horizontal black lines may appear.*/
size(256);
/* How the image is being drawn on a 2D picture. */
currentprojection = perspective(5.0, 4.0, 4.0);
/* Two radii defining the torus. */
real R = 3.0;
real a = 1.3;
/* Material the two torii are made of. */
material blueblob = material(
diffusepen = blue + 0.25*green,
emissivepen = gray(0.2),
specularpen = gray(0.2)
);
material redblob = material(
diffusepen = red,
emissivepen = gray(0.2),
specularpen = gray(0.2)
);
/* Function for drawing the torus. */
triple torus_parameterization(pair t)
{
/* The parameterization is in terms of sine and cosine of 2 pi t.x and *
* 2 pi t.y. Precompute these to avoid repetitive calculations. */
real u = 2.0*pi*t.x;
real v = 2.0*pi*t.y;
real cosu = cos(u);
real cosv = cos(v);
real sinu = sin(u);
real sinv = sin(v);
/* Given the two angles u and v, the x, y, and z coordinates are: */
real x = (R + a*cosv)*cosu;
real y = (R + a*cosv)*sinu;
real z = a*sinv;
/* Return the point (x, y, z), which is a point on the surface. */
triple out = (x, y, z);
return out;
}
/* End of torus_parameterization. */
/* Create the first torus. */
surface t0 = surface(torus_parameterization, (0.0, 0.0), (1.0, 1.0), Spline);
/* The second torus is obtained by rotating and shifting. */
surface t1 = shift((R, 0.0, 0.0))*(rotate(90.0, (1.0, 0.0, 0.0))*t0);
/* Draw both of the torii. */
draw(t0, surfacepen = redblob, render(merge=true));
draw(t1, surfacepen = blueblob, render(merge=true));