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}

旋轉的

相關內容