我正在尝试绘制一个必须经过(0, -1)
、(0, 1)
、(-1, 0)
、(1, 0)
和(1, -1)
的椭圆(-1, 1)
。我的 MWE 如下。我知道,我这里缺少一些数学知识。
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric}
\begin{document}
\begin{tikzpicture}
\draw [help lines] (-2, -2) grid (2, 2);
\draw[rotate=45] (0, 0) ellipse (0.5cm and 1.5cm);
\filldraw[black] (0, 0) circle(1.5pt);
\filldraw[black] (0, 1) circle(1.5pt);
\filldraw[black] (1, 0) circle(1.5pt);
\filldraw[black] (-1, 0) circle(1.5pt);
\filldraw[black] (0, -1) circle(1.5pt);
\filldraw[black] (1, -1) circle(1.5pt);
\filldraw[black] (-1, 1) circle(1.5pt);
\draw[<->] (-2.0, 0) -- (2.0, 0) node[right]{\footnotesize $X_{1}$};
\draw[<->] (0, -1.5) -- (0, 1.5) node[above]{\footnotesize $X_{2}$};
\node[above right] at (0, 1) {\tiny $\left(0, 1\right)$};
\node[above right] at (1, 0) {\tiny $\left(1, 0\right)$};
\node[above left] at (-1, 0) {\tiny $\left(-1, 0\right)$};
\node[below right] at (0, -1) {\tiny $\left(0, -1\right)$};
\node[below right] at (1, -1) {\tiny $\left(1, -1\right)$};
\node[above left] at (-1, 1) {\tiny $\left(-1, 1\right)$};
\end{tikzpicture}
\end{document}
编辑
椭圆的方程是$X_1^2 + X_1 X_2 + X_2^2 = 1$。
答案1
输出
您可以按照 JoeDub 的建议手动执行计算。然后您可以更改
\draw[rotate=45] (0, 0) ellipse (0.5cm and 1.5cm);
进入
\draw[rotate=45] (0, 0) ellipse (0.82cm and 1.4cm);
代码
%http://tex.stackexchange.com/questions/99714/drawing-ellipse-that-passes-through-specified-coordinates#99714
\documentclass[border=5,convert={density=150}]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric}
\begin{document}
\begin{tikzpicture}
\draw [help lines] (-2, -2) grid (2, 2);
\draw[rotate=45,color=blue,very thick] (0, 0) ellipse (0.82cm and 1.4cm);
\foreach \x/\y in {0/0, 0/1, 1/0, -1/0, 0/-1, 1/-1, -1/1}
\filldraw[black] (\x, \y) circle(1.5pt);
\draw[<->] (-2.0, 0) -- (2.0, 0) node[right]{\footnotesize $X_{1}$};
\draw[<->] (0, -1.5) -- (0, 1.5) node[above]{\footnotesize $X_{2}$};
\foreach \x/\y/\direction in {0/1/above right, 1/0/above right, -1/0/above left, 0/-1/below left, 1/-1/below right, -1/1/above left}
\node [\direction] at (\x,\y) {\tiny $\left(\x, \y\right)$};
\end{tikzpicture}
\end{document}
您也可以通过指定长轴和短轴(第一轴和第二轴在手册中)通过使用命令\pgfpathellipse
。这是您的 MWE。
\documentclass[border=5,convert={density=150}]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric}
\begin{document}
\begin{tikzpicture}
\draw [help lines] (-2, -2) grid (2, 2);
\pgfpathellipse{\pgfpointorigin}{\pgfpointxy{1}{-1}}{\pgfpointxy{0.58}{0.58}} % Create an ellipse with one end of major axis passing through (1,-1) and with one end of minor axis at (0.58,0.58)
\pgfusepath{stroke}
\foreach \x/\y in {0/0, 0/1, 1/0, -1/0, 0/-1, 1/-1, -1/1}
\filldraw[black] (\x, \y) circle(1.5pt);
\draw[<->] (-2.0, 0) -- (2.0, 0) node[right]{\footnotesize $X_{1}$};
\draw[<->] (0, -1.5) -- (0, 1.5) node[above]{\footnotesize $X_{2}$};
\foreach \x/\y/\direction in {0/1/above right, 1/0/above right, -1/0/above left, 0/-1/below left, 1/-1/below right, -1/1/above left}
\node [\direction] at (\x,\y) {\tiny $\left(\x, \y\right)$};
\end{tikzpicture}
\end{document}
这里请注意,短半轴的长度大约是的平方根0.58^2 + 0.58^2
。
编辑
我已经使用\foreach
上面的代码来使它们更短。