我想输入类似这张图片的标签 图中多边形A、E、F为等腰直角三角形,B、C、D为边长为1的正方形,G为等边三角形。该图形可沿边折叠,形成以多边形为面的多面体。
我试过
\documentclass[border=1.5mm,12pt]{standalone}
%\usepackage[utf8]{inputenc}
\usepackage{fouriernc}
\usepackage{tkz-euclide,amsmath}
\usetkzobj{all}
\tikzset{hidden/.style = {thick, dashed}}
\begin{document}
\begin{tikzpicture}
\tkzDefPoint(0,0){O}
\tkzDefPoint(1,0){A}
\tkzDefPoint(2,0){B}
\tkzDefPoint(3,0){E}
\tkzDefPoint(1,-1){C}
\tkzDefPoint(0,-1){M}
\tkzDefPoint(2,-1){N}
\tkzDefPoint(1,-2){F}
\tkzDefPoint(1,1){G}
\tkzDefPoint(2,1){H}
\tkzDefPoint(1,2){I}
\tkzDefPointsBy[rotation=center N angle 60](F){D}
%\tkzDrawPoints(A,B,C,D,O,N,E)
%\tkzLabelPoints[above](A,G,H,I)
%\tkzLabelPoints[right](E,D,N,B)
%\tkzLabelPoints[left](A,C,G,F)
\tkzDrawSegments[thick](O,E O,M F,E A,C C,F)
\tkzDrawPolygon[thick](O,M,N,B)
\tkzDrawPolygon[thick](N,F,D)
\tkzDrawPolygon[thick](G,H,I)
\tkzDrawPolygon[thick](A,B,H,G)
\end{tikzpicture}
\end{document}
我怎样才能将标签 A、B、...、F、G 放在中心所有多边形?
答案1
如果您想坚持tkz-euclide
,您可以使用\tkzDefBarycentricPoint
来获取三角形和矩形的中点。不过也有其他可能性。
对于矩形,您可以使用\tkzDefMidPoint(A,B)
,其中A
和B
是两个相对的角。
对于三角形,有不同的“中心点”,可以用\tkzCentroid(A,B,C)
(我认为相同\tkzDefBarycentricPoint(A=1,B=1,C=1)
)、\tkzCircumCenter(A,B,C)
(外接圆中心)和\tkzInCenter(A,B,C)
(内切圆中心)找到。与重心点一样,宏必须跟在后面\tkzGetPoint{<name of point>}
。
您还可以混合使用纯 TikZ 语法,正如我在评论中提到的那样,也可以在您的答案中提到。即使用\node at (barycentric cs:A=1,B=1,C=1) {a};
还要注意,由于绘制多边形的方式,一些顶点的线连接很丑陋:
但这可以通过更仔细地绘制来轻松解决,如下面的代码所示。
\documentclass[border=1.5mm,12pt]{standalone}
\usepackage[utf8]{inputenc}
\usepackage{fouriernc}
\usepackage{tkz-euclide,amsmath}
\usetkzobj{all}
\tikzset{hidden/.style = {thick, dashed}}
\begin{document}
\begin{tikzpicture}
\tkzDefPoint(0,0){o}
\tkzDefPoint(1,0){a}
\tkzDefPoint(2,0){b}
\tkzDefPoint(3,0){e}
\tkzDefPoint(1,-1){c}
\tkzDefPoint(0,-1){m}
\tkzDefPoint(2,-1){n}
\tkzDefPoint(1,-2){f}
\tkzDefPoint(1,1){g}
\tkzDefPoint(2,1){h}
\tkzDefPoint(1,2){i}
\tkzDefPointsBy[rotation=center n angle 60](f){d}
%\tkzLabelPoints[left](o,a,b,c,d,e,f,g,h,i,m,n)
\tkzDrawPolygon[thick](i,h,b,e,n,d,f)
\tkzDrawSegments[thick](n,f g,h)
\tkzDrawPolygon[thick](o,m,n,b)
\tkzDefBarycentricPoint(i=1,h=1,g=1) \tkzGetPoint{A}
\tkzDefBarycentricPoint(g=1,h=1,a=1,b=1) \tkzGetPoint{B}
\tkzDefBarycentricPoint(o=1,a=1,m=1,c=1) \tkzGetPoint{C}
\tkzDefBarycentricPoint(a=1,b=1,c=1,n=1) \tkzGetPoint{D}
\tkzDefBarycentricPoint(b=1,e=1,n=1) \tkzGetPoint{E}
\tkzDefBarycentricPoint(c=1,n=1,f=1) \tkzGetPoint{F}
\tkzDefBarycentricPoint(d=1,n=1,f=1) \tkzGetPoint{G}
\tkzLabelPoints[anchor=center,font=\scriptsize](A,B,C,D,E,F,G)
\end{tikzpicture}
\end{document}
答案2
根据 TorbjørnT 的评论,这是代码
\documentclass[border=1.5mm,12pt]{standalone}
%\usepackage[utf8]{inputenc}
\usepackage{fouriernc}
\usepackage{tkz-euclide,amsmath}
\usetkzobj{all}
\tikzset{hidden/.style = {thick, dashed}}
\begin{document}
\begin{tikzpicture}
\tkzDefPoint(0,0){O}
\tkzDefPoint(1,0){A}
\tkzDefPoint(2,0){B}
\tkzDefPoint(3,0){E}
\tkzDefPoint(1,-1){C}
\tkzDefPoint(0,-1){M}
\tkzDefPoint(2,-1){N}
\tkzDefPoint(1,-2){F}
\tkzDefPoint(1,1){G}
\tkzDefPoint(2,1){H}
\tkzDefPoint(1,2){I}
\tkzDefPointsBy[rotation=center N angle 60](F){D}
\tkzDrawSegments[thick](O,E O,M F,E A,C C,F)
\tkzDrawPolygon[thick](O,M,N,B)
\tkzDrawPolygon[thick](N,F,D)
\tkzDrawPolygon[thick](G,H,I)
\tkzDrawPolygon[thick](C,F,N)
\tkzDrawPolygon[thick](A,B,H,G)
\node at (barycentric cs:N=1,F=1,D=1) {$G$};
\node at (barycentric cs:N=1,B=1,E=1) {$E
$};
\node at (barycentric cs:A=1,B=1,N=1,C=1) {$D$};
\node at (barycentric cs:G=1,H=1,I=1) {$A$};
\node at (barycentric cs:A=1,B=1,H=1,G=1) {$B$};
\node at (barycentric cs:O=1,A=1,M=1,C=1) {$C$};
\node at (barycentric cs:C=1,F=1,N=1) {$G$};
\end{tikzpicture}
\end{document}
答案3
在等待tkz-euclide
答案的过程中,这里有一种方法可以解决同样的问题元帖子. Plain MP 提供了一个center
宏来找到中心边界框任何给定的封闭路径,如果您的路径是三角形,这通常是错误的位置。这里我定义了一个简单的centroid
宏,它将找到三角形路径的质心,从而为标签提供更好的位置。
\RequirePackage{luatex85}
\documentclass[border=5mm]{standalone}
\usepackage{luamplib}
\begin{document}
\mplibtextextlabel{enable}
\begin{mplibcode}
vardef centroid primary trig_path =
save a,b,c,m;
pair a,b,c,m;
a = point 0 of trig_path;
b = point 1 of trig_path;
c = point 2 of trig_path;
m = whatever [a, 1/2[b,c]] = whatever [b, 1/2[a,c]]; m
enddef;
beginfig(1);
path A,B,C,D,E,F,G, t[];
C = unitsquare scaled 100 rotated 15;
D = C shifted point 1 of C;
B = C shifted point 3 of D;
t0 = (point 0 of C -- point 1 of C -- point 3 of C -- cycle);
t1 = t0 rotated -90;
A = t0 shifted point 3 of B;
E = t1 shifted point 2 of D;
F = t1 shifted point 0 of D;
t2 = origin -- point 2 of C -- point 2 of C rotated -60 -- cycle;
G = t2 shifted point 1 of F;
forsuffixes @=A,B,C,D,E,F,G:
draw @;
label(str @, if length @=3: centroid else: center fi @);
endfor
endfig;
\end{mplibcode}
\end{document}
编译此以lualatex
获得luamplib
支持。