TikZ 中的投影坐标放置不正确

TikZ 中的投影坐标放置不正确

我正在尝试画一架飞机。当我画驾驶舱的窗户时,我使用投影点来获得直角。但事情并没有按预期进行。有人能指点我哪里做错了吗?

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\pagestyle{empty}
\begin{document}

\def\aeBodyRadius{0.25cm}
\def\aeBodyNoseDistance{0.21cm}
\begin{tikzpicture}[x=5cm,y=5cm,scale=3,every node={transform shape}]

  \coordinate (TAIL) at (0,0);
  \coordinate (NOSE) at ($(TAIL)+(30:1)$);

  \coordinate (MID)     at ($(TAIL)!0.75!(NOSE)$);

  \coordinate (MID/TOP) at ($(MID)!\aeBodyRadius!90:(NOSE)$);
  \coordinate (MID/BOT) at ($(MID)!\aeBodyRadius!-90:(NOSE)$);

  \coordinate (NOSE/TIP) at ($(NOSE)!\aeBodyNoseDistance!90:(MID)$);

  \coordinate (HIND/TOP) at ($(TAIL)!\aeBodyRadius!90:(NOSE)$);
  \coordinate (HIND/BOT) at ($(TAIL)!\aeBodyRadius!-90:(NOSE)$);

  \node[fill,circle,inner sep=1pt] at (MID/TOP) {};
  \node[fill,circle,inner sep=1pt] at (MID/BOT) {};
  \node[fill,circle,inner sep=1pt] at (HIND/TOP) {};
  \node[fill,circle,inner sep=1pt] at (HIND/BOT) {};

  \draw[rounded corners=10pt] 
                             (HIND/TOP) --
                             (MID/TOP)  --
                             node [pos=0.25] (WINDOW/TOP/N) {}
                             node [pos=0.50] (WINDOW/BOT/N) {}
                             (NOSE/TIP) -- 
                             (MID/BOT)  --
                             (HIND/BOT);
    \coordinate (WINDOW/TOP) at (WINDOW/TOP/N.center);
    \coordinate (WINDOW/BOT) at (WINDOW/BOT/N.center);

    \coordinate (WINDOW/RIG/T) at ($(TAIL)!(WINDOW/TOP)!(NOSE)$);
    \coordinate (WINDOW/RIG)   at ($(WINDOW/TOP)!(WINDOW/BOT)!(WINDOW/RIG/T)$);

    \draw (WINDOW/TOP) -- (WINDOW/RIG) -- (WINDOW/BOT);

    \draw[red] (TAIL) -- (NOSE);

\end{tikzpicture}

\end{document}

在此处输入图片描述

飞机中心的“红”线清楚地显示了我的垂直并不是它应该的样子。

更新

似乎不是可以正常工作的代码片段如下:

    \coordinate (WINDOW/RIG/T) at ($(TAIL)!(WINDOW/TOP)!(NOSE)$);
    \coordinate (WINDOW/RIG)   at ($(WINDOW/TOP)!(WINDOW/BOT)!(WINDOW/RIG/T)$);

投影点似乎没有位于适当的垂直线上。具体来说, (WINDOW/RIG)应该位于红线上方,因为通过(WINDOW/TOP)和 的线应该垂直于通过和 的(WINDOW/RIG/T)红线。(TAIL)(NOSE)

答案1

正如所提到的艾利特,误差是由 引起的\pgfpointnormalised。本文给出了一种获得更好精度的解决方案回答

应用于MWE:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\pagestyle{empty}

% use the Mark Wibrow's correction
\makeatletter
\def\pgfpointnormalised#1{%
\pgf@process{#1}%
\pgfmathatantwo{\the\pgf@y}{\the\pgf@x}%
\let\pgf@tmp=\pgfmathresult%
\pgfmathcos@{\pgf@tmp}\pgf@x=\pgfmathresult pt\relax%
\pgfmathsin@{\pgf@tmp}\pgf@y=\pgfmathresult pt\relax%
}
\makeatother

\begin{document}

\def\aeBodyRadius{0.25cm}
\def\aeBodyNoseDistance{0.21cm}
\begin{tikzpicture}[x=5cm,y=5cm,scale=3,every node={transform shape}]

  \coordinate (TAIL) at (0,0);
  \coordinate (NOSE) at ($(TAIL)+(30:1)$);

  \coordinate (MID)     at ($(TAIL)!0.75!(NOSE)$);

  \coordinate (MID/TOP) at ($(MID)!\aeBodyRadius!90:(NOSE)$);
  \coordinate (MID/BOT) at ($(MID)!\aeBodyRadius!-90:(NOSE)$);

  \coordinate (NOSE/TIP) at ($(NOSE)!\aeBodyNoseDistance!90:(MID)$);

  \coordinate (HIND/TOP) at ($(TAIL)!\aeBodyRadius!90:(NOSE)$);
  \coordinate (HIND/BOT) at ($(TAIL)!\aeBodyRadius!-90:(NOSE)$);

  \node[fill,circle,inner sep=1pt] at (MID/TOP) {};
  \node[fill,circle,inner sep=1pt] at (MID/BOT) {};
  \node[fill,circle,inner sep=1pt] at (HIND/TOP) {};
  \node[fill,circle,inner sep=1pt] at (HIND/BOT) {};

  \draw[rounded corners=10pt] 
                             (HIND/TOP) --
                             (MID/TOP)  --
                             node [pos=0.25] (WINDOW/TOP/N) {}
                             node [pos=0.50] (WINDOW/BOT/N) {}
                             (NOSE/TIP) -- 
                             (MID/BOT)  --
                             (HIND/BOT);
    \coordinate (WINDOW/TOP) at (WINDOW/TOP/N.center);
    \coordinate (WINDOW/BOT) at (WINDOW/BOT/N.center);

    \coordinate (WINDOW/RIG/T) at ($(TAIL)!(WINDOW/TOP)!(NOSE)$);
    \coordinate (WINDOW/RIG)   at ($(WINDOW/TOP)!(WINDOW/BOT)!(WINDOW/RIG/T)$);

    \draw (WINDOW/TOP) -- (WINDOW/RIG) -- (WINDOW/BOT);

    \draw[red] (TAIL) -- (NOSE);

\end{tikzpicture}

\end{document}

在此处输入图片描述

答案2

您可能打算将 WINDOW/RIG/T 沿主轴放置,但这样做是可行的。(如果它没坏……)

呜呜!

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\pagestyle{empty}
\begin{document}
\def\aeBodyRadius{0.25cm}
\def\aeBodyNoseDistance{0.21cm}
\begin{tikzpicture}[x=5cm,y=5cm,scale=3,every node={transform shape}]
  \coordinate (TAIL) at (0,0);
  \coordinate (NOSE) at ($(TAIL)+(30:1)$);
  \coordinate (MID)     at ($(TAIL)!0.75!(NOSE)$);
  \coordinate (MID/TOP) at ($(MID)!\aeBodyRadius!90:(NOSE)$);
  \coordinate (MID/BOT) at ($(MID)!\aeBodyRadius!-90:(NOSE)$);
  \coordinate (NOSE/TIP) at ($(NOSE)!\aeBodyNoseDistance!90:(MID)$);
  \coordinate (HIND/TOP) at ($(TAIL)!\aeBodyRadius!90:(NOSE)$);
  \coordinate (HIND/BOT) at ($(TAIL)!\aeBodyRadius!-90:(NOSE)$);
  \node[fill,circle,inner sep=1pt] at (MID/TOP) {};
  \node[fill,circle,inner sep=1pt] at (MID/BOT) {};
  \node[fill,circle,inner sep=1pt] at (HIND/TOP) {};
  \node[fill,circle,inner sep=1pt] at (HIND/BOT) {};
  \draw[rounded corners=10pt] 
                             (HIND/TOP) --
                             (MID/TOP)  --
                             node [pos=0.25] (WINDOW/TOP/N) {}
                             node [pos=0.50] (WINDOW/BOT/N) {}
                             (NOSE/TIP) -- 
                             (MID/BOT)  --
                             (HIND/BOT);
  \coordinate (WINDOW/TOP) at (WINDOW/TOP/N.center);
  \coordinate (WINDOW/BOT) at (WINDOW/BOT/N.center);

%start of modifications
   \coordinate (WINDOW/RIG/T) at ($(TAIL)!(WINDOW/TOP)!90:(NOSE)$);
   \coordinate (WINDOW/RIG)   at ($(WINDOW/TOP)!(WINDOW/BOT)!90:(WINDOW/RIG/T)$);
   \node[fill,circle,inner sep=1pt] at (WINDOW/RIG/T) {};% way down near the tail
   \draw[blue] (WINDOW/TOP) -- (WINDOW/RIG) -- (WINDOW/BOT);
%end of modifications

   \draw[red] (TAIL) -- (NOSE);

\end{tikzpicture}

\end{document}

答案3

为了说明将其平整绘制并旋转的含义:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\pagestyle{empty}

\newlength{\myx}
\newlength{\myy}

\begin{document}
\def\aeBodyRadius{0.25cm}
\def\aeBodyNoseDistance{0.21cm}
\begin{tikzpicture}[x=5cm,y=5cm,scale=3,every node={transform shape},rotate=30]% changed here
  \coordinate (TAIL) at (0,0);
  \coordinate (NOSE) at ($(TAIL)+(1,0)$);% changed here
  \coordinate (MID)     at ($(TAIL)!0.75!(NOSE)$);
  \coordinate (MID/TOP) at ($(MID)!\aeBodyRadius!90:(NOSE)$);
  \coordinate (MID/BOT) at ($(MID)!\aeBodyRadius!-90:(NOSE)$);
  \coordinate (NOSE/TIP) at ($(NOSE)!\aeBodyNoseDistance!90:(MID)$);
  \coordinate (HIND/TOP) at ($(TAIL)!\aeBodyRadius!90:(NOSE)$);
  \coordinate (HIND/BOT) at ($(TAIL)!\aeBodyRadius!-90:(NOSE)$);
  \node[fill,circle,inner sep=1pt] at (MID/TOP) {};
  \node[fill,circle,inner sep=1pt] at (MID/BOT) {};
  \node[fill,circle,inner sep=1pt] at (HIND/TOP) {};
  \node[fill,circle,inner sep=1pt] at (HIND/BOT) {};
  \draw[rounded corners=10pt] 
                             (HIND/TOP) --
                             (MID/TOP)  --
                             node [pos=0.25] (WINDOW/TOP/N) {}
                             node [pos=0.50] (WINDOW/BOT/N) {}
                             (NOSE/TIP) -- 
                             (MID/BOT)  --
                             (HIND/BOT);
  \coordinate (WINDOW/TOP) at (WINDOW/TOP/N.center);
  \coordinate (WINDOW/BOT) at (WINDOW/BOT/N.center);

  \node[fill,circle,inner sep=1pt] at (NOSE) {};
  \node[fill,circle,inner sep=1pt] at (TAIL) {};
  \coordinate (WINDOW/RIG/T) at ($(TAIL)!(WINDOW/TOP)!(NOSE)$);
  \coordinate (WINDOW/RIG)   at ($(WINDOW/TOP)!(WINDOW/BOT)!(WINDOW/RIG/T)$);
  \node[fill,circle,inner sep=1pt] at (WINDOW/RIG/T) {};
  \draw[blue] (WINDOW/TOP) -- (WINDOW/RIG) -- (WINDOW/BOT);
  \draw[red] (TAIL) -- (NOSE);

\end{tikzpicture}

\end{document}

旋转

相关内容