答案1
Tikz 一开始可能让人不知所措。我为您提供的解决方案可能不是最优雅的(从程序员的角度来看),但从几何角度来看很容易理解。
- Filldraw 用于绘制点,draw 用于在两点之间绘制线。这些都是基本命令。
- 我用形状.几何库对于创建正多边形非常有帮助。此外,我还可以非常轻松地引用多边形的每个角(并且我命名了它们的坐标,以便更容易识别)。
- 另一个是计算,用于计算坐标(在本例中是另外两点之间的中点)。
\documentclass{standalone}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric,calc}
\begin{document}
\begin{tikzpicture}
\node[thick,regular polygon,regular polygon sides=5, minimum size=4cm,draw] (poli) at (0,0) {};
\coordinate (v1) at (poli.corner 2);
\coordinate (v2) at (poli.corner 3);
\coordinate (v3) at (poli.corner 4);
\coordinate (v4) at (poli.corner 5);
\coordinate (v5) at (poli.corner 1);
\filldraw (v1) node[left]{$v_1$} circle (2pt);
\filldraw (v2) node[left]{$v_2$} circle (2pt);
\filldraw (v3) node[right]{$v_3$} circle (2pt);
\filldraw (v4) node[right]{$v_4$} circle (2pt);
\filldraw (v5) node[above]{$v_5$} circle (2pt);
\draw (v1) -- (v3)
(v1) -- (v4)
(v2) -- (v4)
(v2) -- (v5)
(v3) -- (v5);
\coordinate (u1) at ($0.5*(v2)+0.5*(v5)$);
\coordinate (u2) at ($0.5*(v1)+0.5*(v3)$);
\coordinate (u3) at ($0.5*(v2)+0.5*(v4)$);
\coordinate (u4) at ($0.5*(v3)+0.5*(v5)$);
\coordinate (u5) at ($0.5*(v1)+0.5*(v4)$);
\coordinate (w) at (poli.center);
\filldraw (u1) node[left]{$u_1$} circle (2pt);
\filldraw (u2) node[left]{$u_2$} circle (2pt);
\filldraw (u3) node[right]{$u_3$} circle (2pt);
\filldraw (u4) node[right]{$u_4$} circle (2pt);
\filldraw (u5) node[above]{$u_5$} circle (2pt);
\filldraw (w) node[right]{$w$} circle (2pt);
\draw (u1) -- (w)
(u2) -- (w)
(u3) -- (w)
(u4) -- (w)
(u5) -- (w);
\end{tikzpicture}
\end{document}
结果如下:
答案2
由于您已经有了 tikz 解决方案,因此我添加了 MetaFun 解决方案。我不知道如何将其转换为 tikz,但也许您有想法(或者其他人可以利用它)。我只做第三个,因为如果知道如何做,中间的那个可能很容易做。
\startMPpage[offset=1dk]
u := 4cm ;
path p ; p := for i = 0 upto 4 : (0,u) rotatedaround(origin, 72*i) -- endfor cycle ;
draw p withpen pencircle scaled 1 ;
for i = 0 upto 4 :
draw (point i of p) -- (point i + 2 of p) withcolor darkyellow ;
draw (origin -- 0.5[point i of p, point i+2 of p]) withcolor darkred ;
drawdot point i of p withstacking 2 withpen pencircle scaled 4 withcolor darkgreen ;
drawdot 0.5[point i of p, point i+2 of p] withstacking 2 withpen pencircle scaled 4 withcolor darkblue ;
endfor
for i = 1 upto 5 :
freelabel("$v_{" & decimal i & "}$", point i of p, origin ) ;
freelabel("$u_{" & decimal i & "}$", 0.5[point i-1 of p, point i+1 of p], origin ) ;
endfor
drawdot origin withstacking 2 withpen pencircle scaled 4 ;
label.rt("$w_4$", (0.05u,-0.05u) ) ;
\stopMPpage
运行context
此文件得到以下结果:
我添加了一些颜色,只是为了更容易看清什么是什么。这也导致了一些排序问题,通过在另一层添加点(使用withstacking
)解决了这个问题。最后一个标签是经过反复试验后放置的。
答案3
\foreach
基于纯 Ti 的解决方案钾Z,不需要库。首先我们放置坐标,然后绘制所有坐标。
\documentclass[tikz,border=2mm]{standalone}
% the vertex at \y places from \x vertex
% example nextvertex(4,2) = 1 --> ...,4,5,1,...
\tikzset{declare function={nextvertex(\x,\y)=int(mod(\x+\y-1,5)+1);}}
\begin{document}
\begin{tikzpicture}
\foreach\i in {1,...,5} % coordinates
\path (0,0) -- (90+72*\i:{2*sin(18)}) coordinate (u\i) node[pos=1.35] {$u_\i$}
-- (90+72*\i:2) coordinate (v\i) node[pos=1.15] {$v_\i$};
\foreach\i in {1,...,5}
{% lines and points
\pgfmathtruncatemacro\j{nextvertex(\i,1)}
\pgfmathtruncatemacro\k{nextvertex(\i,2)}
\draw[thick] (v\i) -- (v\j);
\draw (v\i) -- (v\k);
\draw (0,0) -- (u\i);
\fill (v\i) circle (1pt);
\fill (u\i) circle (1pt);
}
\end{tikzpicture}
\end{document}
答案4
您不需要\graph
为此使用,只需使用简单的\node
和\draw
:
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[blacknode/.style={fill, circle, minimum size=1mm, inner sep=0pt}]
\node [blacknode] (a) at (0, 0) {};
\node [blacknode] (b) at (1, 1) {};
\draw (a) -- (b);
% add more nodes and edges as needed
\end{tikzpicture}
\end{document}
(或者尝试阅读 VisualTikZ 以获得快速参考)
在这种情况下,图表确实很难(即使你用“普通”编程语言编写程序来计算坐标,这也是非常困难的)......
我稍微作弊了一下,使用 GeoGebra 来计算相关距离(角度显然是 72 度的倍数):
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[blacknode/.style={fill, circle, minimum size=1mm, inner sep=0pt}, labelnode/.style={font=\tiny}]
\def\largeLength{1.7013}
\def\smallLength{0.52573}
\path
(0, 0) node [blacknode] (w4) {} node [labelnode, above] {w4}
(90:\smallLength) node [blacknode] (u5) {} node [labelnode, above] {u5}
(90+72:\smallLength) node [blacknode] (u1) {} node [labelnode, above] {u1}
(90+72*2:\smallLength) node [blacknode] (u2) {} node [labelnode, above] {u2}
(90+72*3:\smallLength) node [blacknode] (u3) {} node [labelnode, above] {u3}
(90+72*4:\smallLength) node [blacknode] (u4) {} node [labelnode, above] {u4}
(90:\largeLength) node [blacknode] (v5) {} node [labelnode, above] {v5}
(90+72:\largeLength) node [blacknode] (v1) {} node [labelnode, above] {v1}
(90+72*2:\largeLength) node [blacknode] (v2) {} node [labelnode, below] {v2}
(90+72*3:\largeLength) node [blacknode] (v3) {} node [labelnode, below] {v3}
(90+72*4:\largeLength) node [blacknode] (v4) {} node [labelnode, above] {v4}
;
\draw [thick] (v1) -- (v2) -- (v3) -- (v4) -- (v5) -- (v1); % I don't know why "cycle" doesn't work here but anyway
\draw (v1) -- (v4) -- (v2) -- (v5) -- (v3) -- (v1);
\draw (w4) -- (u1);
\draw (w4) -- (u2);
\draw (w4) -- (u3);
\draw (w4) -- (u4);
\draw (w4) -- (u5);
\end{tikzpicture}
\end{document}
然而,调整标签的位置需要一些手动工作。