尺寸对于简单的 3D 图片来说太大

尺寸对于简单的 3D 图片来说太大

我创建了这个简单的 3D 框。一切看起来都符合预期,但我一直收到错误

Dimension too large.

有什么方法可以避免吗?在此处输入图片描述

梅威瑟:

\documentclass{standalone}

\usepackage{tikz}
\usetikzlibrary{intersections}

\begin{document}
\def\anga{22.5}
\def\angb{-135}
\begin{tikzpicture}[x={({-sin(\angb)*1cm},{cos(\angb)*sin(\anga)*1cm})},y={({-cos(\angb)*1cm},{-sin(\angb)*sin(\anga)*1cm})},z={(0cm,{cos(\anga)*1cm})},scale=0.4]

\draw (10,7.5,0) -- (0,7.5,0) -- (0,0,0) -- (10,0,0) -- cycle;
\path[name path=above,blue]  (0,0,0) -- (10,0,0) -- (10,7.5,0);
\path[name path=below,red] (10,7.5,-1.5) -- (0,7.5,-1.5) -- (0,0,-1.5);
\draw[name intersections={of=above and below}] (intersection-1) -- (0,7.5,-1.5) -- (intersection-2);
\draw (0,0,0) -- (0,0,-1.5) -- (10,0,-1.5) -- (10,7.5,-1.5) -- (10,7.5,0) (10,0,-1.5) -- (10,0,0) (0,7.5,-1.5) -- (0,7.5,0);
\draw[densely dashed] (intersection-1) -- (0,0,-1.5) (intersection-2) -- (10,7.5,-1.5);

\end{tikzpicture}
\end{document}

答案1

这是一件很奇怪的事情。我怀疑有以下情况:

您的两条路径均包含两个段:

  • 沿着X轴和
  • 沿着轴。

这意味着每条路径都包含与另一条路径的线段平行的线段。这些线段永远不会相交,尽管库确实有一些检查来防止尝试计算平行线之间的交点,但由于 TeX 的不精确性,在您的特定情况下,此检查似乎失败了,或者这些线段不再严格平行。使用scale=0.39994.01将稍微改变数字,以便库的检查再次起作用,或者这些线将再次被正确标记为平行。

我将为您提供两种解决方法:

  1. 构造四条路径并仅找到不(几乎)平行的路径之间的交点:

     \path[name path=above1,blue] (0,0,0) -- (10,0,0);
     \path[name path=above2,blue] (10,0,0) -- (10,7.5,0);
     \path[name path=below1,red] (0,7.5,-1.5) -- (0,0,-1.5);
     \path[name path=below2,red] (10,7.5,-1.5) -- (0,7.5,-1.5);
     \draw[name intersections={of=above1 and below1, by=i1},
           name intersections={of=above2 and below2, by=i2}]
           (i1) -- (0,7.5,-1.5) -- (i2);
    
  2. 使用intersection cs或其隐式版本intersection of(手册中不再记录,它只能找到之间的交集线- 和不是线段——由线上的两个点和圆形节点定义。

     \coordinate (intersection-1)
       at (intersection of 0,0,0--10,0,0 and 0,0,-1.5--0,10,-1.5)
      coordinate (intersection-2)
       at (intersection of 10,7.5,0--10,0,0 and 10,7.5,-1.5--0,7.5,-1.5);
    

    这不需要库,但涉及圆形节点时intersections需要库。calc

    顺便一提,

     \path (intersection of 0,0--0,1 and 1,0--1.00001,1);
    

    Dimension too large.由于其交点距离很远,也会触发错误。

代码

\documentclass[tikz]{standalone}
\usetikzlibrary{intersections}
\tikzset{
  Pyg cs/.style 2 args={
    x={({-sin(#2)*1cm},{cos(#2)*sin(#1)*1cm})},
    y={({-cos(#2)*1cm},{-sin(#2)*sin(#1)*1cm})},
    z={(0cm,{cos(#1)*1cm})}}}

\begin{document}
\begin{tikzpicture}[Pyg cs={22.5}{-135}, scale=0.4]
\draw (10,7.5,0) -- (0,7.5,0) -- (0,0,0) -- (10,0,0) -- cycle;
\path[name path=above1,blue] (0,0,0) -- (10,0,0);
\path[name path=above2,blue] (10,0,0) -- (10,7.5,0);
\path[name path=below1,red] (0,7.5,-1.5) -- (0,0,-1.5);
\path[name path=below2,red] (10,7.5,-1.5) -- (0,7.5,-1.5);
\draw[name intersections={of=above1 and below1, by=i1},
      name intersections={of=above2 and below2, by=i2}]
      (i1) -- (0,7.5,-1.5) -- (i2);
\draw (0,0,0) -- (0,0,-1.5) -- (10,0,-1.5) -- (10,7.5,-1.5) -- (10,7.5,0)
      (10,0,-1.5) -- (10,0,0) (0,7.5,-1.5) -- (0,7.5,0);
\draw[densely dashed] (i1) -- (0,0,-1.5) (i2) -- (10,7.5,-1.5);
\end{tikzpicture}

\begin{tikzpicture}[Pyg cs={22.5}{-135}, scale=0.4]
\draw (10,7.5,0) -- (0,7.5,0) -- (0,0,0) -- (10,0,0) -- cycle;
\coordinate (intersection-1)
  at (intersection of 0,0,0--10,0,0 and 0,0,-1.5--0,10,-1.5)
 coordinate (intersection-2)
  at (intersection of 10,7.5,0--10,0,0 and 10,7.5,-1.5--0,7.5,-1.5);
\draw (intersection-1) -- (0,7.5,-1.5) -- (intersection-2)
      (0,0,0) -- (0,0,-1.5) -- (10,0,-1.5) -- (10,7.5,-1.5) -- (10,7.5,0)
      (10,0,-1.5) -- (10,0,0) (0,7.5,-1.5) -- (0,7.5,0);
\draw[densely dashed] (intersection-1) -- (0,0,-1.5)
                      (intersection-2) -- (10,7.5,-1.5);
\end{tikzpicture}
% \tikz\path(intersection of 0,0--0,1 and 1,0--1.00001,1);
\end{document}

答案2

您可以使用3d工具

\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{3dtools}%https://github.com/marmotghost/tikz-3dtools
\begin{document}
    \begin{tikzpicture}[3d/install view={phi=140,theta=70},line cap=butt,line join=round,c/.style={circle,fill,inner sep=1pt},
        declare function={a=4;b=3;c=.5;}] 
\path (0,0,0) coordinate (A)
(a,0,0) coordinate (B)
(a,b,0) coordinate (C)
(0,b,0) coordinate (D)
(0,0,c) coordinate (A')
(a,0,c) coordinate (B')
(a,b,c) coordinate (C')
(0,b,c) coordinate (D')
;
    %\path foreach \p/\g in {A/180,B/-90,C/0,D/90,A'/180,B'/-90,C'/0,D'/90}
%{(\p)node[c]{}+(\g:2.5mm) node{$\p$}};
\draw[3d/visible] (A') -- (B') -- (C') -- (D') --cycle (A) -- (A');
\path[save named path=rec1]
(B) -- (B') -- (C') -- (C) --cycle; 
\path[save named path=rec2]
(C) -- (C') -- (D') -- (D) --cycle;
\path[save named path=lBA]
(B) -- (A); 
\path[save named path=lDA]
(D) -- (A);
\tikzset{3d/draw ordered paths={lBA,rec1}}
\tikzset{3d/draw ordered paths={lDA,rec2}}
    \end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容