答案1
\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[scale=0.7]
\draw[line width=0.3mm, -stealth] (0,-4)--(0,4);
\draw[line width=0.3mm, -stealth] (-4,0)--(4,0);
\draw[-stealth, domain=0:540, variable=\t,samples=200, line width=0.7mm]
plot ({-cos(\t)+2*cos(2*\t)}, {sin(\t)+2*sin(2*\t)});
\draw[fill=white, line width=0.5mm] (0,0) circle[radius=0.25 em];
\draw[fill=white, line width=0.5mm] (2,0) circle[radius=0.25 em];
\draw(-0.3,-0.1) node[below]{$0$};
\draw(2,0.1) node[above]{$1$};
\end{tikzpicture}
\end{document}
答案2
答案3
这是我做的两种方法,但我认为第二种方法更接近您想要的。
\documentclass{standalone}
\usepackage{tikz}
\usepackage{xcolor}
\definecolor{sidecolor}{HTML}{E7E7E7}
\begin{document}
\begin{tikzpicture}[very thick]
\draw[gray!30] (-2,-2) grid (2,2);
\draw (1.3,0) .. controls (1,0.8) and (0,0.5) .. (-0.5,0);
\draw[cm={1,0,0,-1,(0,0)}] (1.3,0) .. controls (1,0.8) and (0,0.5) .. (-0.5,0);
\draw[rotate=120] (1.3,0) .. controls (1,0.8) and (0,0.5) .. (-0.5,0);
\draw[cm={1,0,0,-1,(0,0)},rotate=240] (1.3,0) .. controls (1,0.8) and (0,0.5) .. (-0.5,0);
\draw[rotate=240] (1.3,0) .. controls (1,0.8) and (0,0.5) .. (-0.5,0);
\draw[cm={1,0,0,-1,(0,0)},rotate=120] (1.3,0) .. controls (1,0.8) and (0,0.5) .. (-0.5,0);
\end{tikzpicture}
\begin{tikzpicture}[very thick]
\draw[gray!30] (-2,-2) grid (2,2);
\draw (1.3,0) to[out=90,in=60] (-0.5,0);
\draw[cm={1,0,0,-1,(0,0)}] (1.3,0) to[out=90,in=60] (-0.5,0);
\draw[rotate=120] (1.3,0) to[out=90,in=60] (-0.5,0);
\draw[cm={1,0,0,-1,(0,0)},rotate=240] (1.3,0) to[out=90,in=60] (-0.5,0);
\draw[rotate=240] (1.3,0) to[out=90,in=60] (-0.5,0);
\draw[cm={1,0,0,-1,(0,0)},rotate=120] (1.3,0) to[out=90,in=60] (-0.5,0);
\end{tikzpicture}
\end{document}
答案4
一个 SkiaSharp 解决方案,只是为了好玩!我们可以编译以下内容,\immediate\write18
使其与 TeX 更相关。
using CSharpMath.SkiaSharp;
using SkiaSharp;
using System.Diagnostics;
using static System.MathF;
class Diagram
{
const float scale = SKDocument.DefaultRasterDpi / 2.54f; // dots per cm
static float PtToCm(float pt) => pt / scale;
static readonly SKPaint strokeBlack = new SKPaint
{
Style = SKPaintStyle.Stroke,
StrokeWidth = PtToCm(0.8f),
Color = SKColors.Black,
StrokeCap = SKStrokeCap.Round,
IsAntialias = true
};
static readonly SKPaint strokeRed = new SKPaint
{
Style = SKPaintStyle.Stroke,
StrokeWidth = PtToCm(0.8f),
Color = SKColors.Red,
StrokeCap = SKStrokeCap.Round,
IsAntialias = true
};
static readonly SKPaint fillGreen = new SKPaint
{
Style = SKPaintStyle.Fill,
StrokeWidth = PtToCm(0.8f),
Color = SKColors.Green,
StrokeCap = SKStrokeCap.Round,
IsAntialias = true
};
static readonly SKRect domain = new SKRect(-5f, 5f, 5f, -5f);
static readonly float width = domain.Width * scale;
static readonly float height = -domain.Height * scale;
public static void Generate(string filename)
{
using (var stream = new SKFileWStream($"{filename}.pdf"))
using (var document = SKDocument.CreatePdf(stream))
using (var canvas = document.BeginPage(width, height))
{
canvas.Scale(scale, -scale);
canvas.Translate(-domain.Left, -domain.Top);
canvas.DrawLine(domain.Left + 0.5f, 0, domain.Right - 0.5f, 0, strokeBlack);
canvas.DrawLine(0, domain.Bottom + 0.5f, 0, domain.Top - 0.5f, strokeBlack);
int N = 100;
int start = 0; // degrees
int stop = 360; // degrees
float d = (stop - start) * PI / (180 * N);
SKPoint[] pts = Enumerable
.Range(0, N)
.Select(i => new SKPoint
{
X = -Cos(i * d) + 2 * Cos(2 * i * d),
Y = Sin(i * d) + 2 * Sin(2 * i * d)
})
.ToArray();
for (int i = 0; i < N; ++i)
canvas.DrawLine(pts[i], pts[(i + 1) % N], strokeRed);
canvas.DrawCircle(1, 0, PtToCm(2), fillGreen);
MathPainterExtension.Painter.FontSize = PtToCm(12);
canvas.Draw("1", 1.3f, PtToCm(10));
MathPainterExtension.Painter.FontSize = PtToCm(8);
canvas.Draw(@"\begin{cases} x(t) = -\cos t + 2 \cos (2t) \\ y(t) = \sin t + 2 \sin (2t) \end{cases}", 2.5f, 4);
document.EndPage();
}
}