我想画这幅画(GeoGebra 草图)在 tikz 中,这是我目前拥有的
图片编译如下,看起来有点乱,因为我只能指定一整条线是实线还是虚线,不符合现实关系。有没有什么办法可以改善它?
我的代码如下所示:
\documentclass[border=0.2pt]{standalone}
\usepackage{pgfplots}
\usepackage{tikz-3dplot}
\usetikzlibrary{patterns,arrows,positioning,3d,calc,fadings,shapes,decorations.markings,arrows.meta}
\usepackage{tikz,times,amsmath}
\begin{document}
\tdplotsetmaincoords{85}{20}
\begin{tikzpicture}[yscale=2,xscale=2,line width=0.5pt, tdplot_main_coords]
\coordinate (A) at (0,0,0);
\coordinate (B) at (1,0,0);
\coordinate (C) at (2,0,0);
\coordinate (D) at (1,0,1);
\coordinate (X) at (0,0,-1);
\coordinate (H) at (1,0,-1);
\coordinate (Y) at (2,0,1);
\coordinate (A1) at (2,0,2);
\coordinate (B1) at (2,1,2);
\coordinate (C1) at (0,1,2);
\coordinate (D1) at (0,0,2);
\coordinate (E) at (1,-0.87,0.5);
\coordinate (X4) at (0,-0.87,0.5);
\coordinate (F) at (1,0.87,0.5);
\coordinate (X5) at (0,0.87,0.5);
\coordinate (X6) at (1,-0.87,1.5);
\coordinate (X7) at (1,0.87,1.5);
\coordinate (G) at (1,-0.87,-0.5);
\coordinate (I) at (1,-1.73,0);
\coordinate (Y2) at (1,-0.87,-1.5);
\coordinate (Y3) at (2,-0.87,-0.5);
\coordinate (Y4) at (2,0.87,-0.5);
\coordinate (Y5) at (1,0.87,-0.5);
\coordinate (J) at (1,1.73,0);
\coordinate (Y6) at (1,0.87,-1.5);
\coordinate (K) at (2,0,-1);
\coordinate (M) at (2,1,1);
\coordinate (N) at (1,0,1);
\draw[rounded corners=0.05pt](A)circle (0.25pt)node[left=-2pt]{$A$}
(B)circle (0.25pt)node[below]{$B$}
(C)circle (0.25pt)node[below]{$C$}
(D)circle (0.25pt)node[below]{$D$}
(E)circle (0.25pt)node[below]{$E$}
(F)circle (0.25pt)node[below]{$F$}
(G)circle (0.25pt)node[below]{$G$}
(H)circle (0.25pt)node[below]{$H$}
(I)circle (0.25pt)node[below]{$I$}
(J)circle (0.25pt)node[below]{$J$}
(X)--(A)--(X4)--(E)--(I)--(G)--(B)--(E)--(X6)--(D)--(B)
(F)--(X7)--(D)
(G)--(Y3)--(C)--(B)--(G)--(Y2)--(H)--(Y6)--(Y5)
(Y4)--(C)--(Y)--(D)
;
\draw[thin,dash pattern=on 2pt off 2pt]
(A)--(B)--(F)--(X5)--(A)
(X)--(H)--(B)--(F)--(J)--(Y5)--(Y4)
(B)--(Y5);
\end{tikzpicture}
\end{document}
答案1
我intersections
用过定义两条路径:AB 和 EI。然后,我计算了交点,即名为 的坐标x
。剩下的就是绘制两条线段 A--x--B(红色),一条为虚线,另一条为虚线。
您还可以玩dash pattern
选项。
\documentclass[border=0.2pt]{standalone}
\usepackage{pgfplots}
\usepackage{tikz-3dplot}
\usetikzlibrary{patterns,arrows,positioning,3d,calc,fadings,shapes,decorations.markings,arrows.meta}
\usepackage{tikz,times,amsmath}
\usetikzlibrary{intersections}
\begin{document}
\tdplotsetmaincoords{85}{20}
\begin{tikzpicture}[yscale=2,xscale=2,line width=0.5pt, tdplot_main_coords]
\coordinate (A) at (0,0,0);
\coordinate (B) at (1,0,0);
\coordinate (C) at (2,0,0);
\coordinate (D) at (1,0,1);
\coordinate (X) at (0,0,-1);
\coordinate (H) at (1,0,-1);
\coordinate (Y) at (2,0,1);
\coordinate (A1) at (2,0,2);
\coordinate (B1) at (2,1,2);
\coordinate (C1) at (0,1,2);
\coordinate (D1) at (0,0,2);
\coordinate (E) at (1,-0.87,0.5);
\coordinate (X4) at (0,-0.87,0.5);
\coordinate (F) at (1,0.87,0.5);
\coordinate (X5) at (0,0.87,0.5);
\coordinate (X6) at (1,-0.87,1.5);
\coordinate (X7) at (1,0.87,1.5);
\coordinate (G) at (1,-0.87,-0.5);
\coordinate (I) at (1,-1.73,0);
\coordinate (Y2) at (1,-0.87,-1.5);
\coordinate (Y3) at (2,-0.87,-0.5);
\coordinate (Y4) at (2,0.87,-0.5);
\coordinate (Y5) at (1,0.87,-0.5);
\coordinate (J) at (1,1.73,0);
\coordinate (Y6) at (1,0.87,-1.5);
\coordinate (K) at (2,0,-1);
\coordinate (M) at (2,1,1);
\coordinate (N) at (1,0,1);
\draw[rounded corners=0.05pt](A)circle (0.25pt)node[left=-2pt]{$A$}
(B)circle (0.25pt)node[below]{$B$}
(C)circle (0.25pt)node[below]{$C$}
(D)circle (0.25pt)node[below]{$D$}
(E)circle (0.25pt)node[below]{$E$}
(F)circle (0.25pt)node[below]{$F$}
(G)circle (0.25pt)node[below]{$G$}
(H)circle (0.25pt)node[below]{$H$}
(I)circle (0.25pt)node[below]{$I$}
(J)circle (0.25pt)node[below]{$J$};
\draw
(X)--(A)--(X4)--(E)--(I)--(G)--(B)--(E)--(X6)--(D)--(B)
(F)--(X7)--(D)
(G)--(Y3)--(C)--(B)--(G)--(Y2)--(H)--(Y6)--(Y5)
(Y4)--(C)--(Y)--(D)
;
\draw[thin,dash pattern=on 2pt off 2pt]
(B)--(F)--(X5)--(A) % <--------- removed (A)--
(X)--(H)--(B)--(F)--(J)--(Y5)--(Y4)
(B)--(Y5);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\path [name path=AB] (A)--(B);
\path [name path=EI] (E)--(I);
\path [red,name intersections={of = AB and EI, by = x}];
\draw [red](A)--(x); \draw [red,dashed] (x)--(B);
\end{tikzpicture}
\end{document}