TikZ 不計算交集

TikZ 不計算交集

我正在嘗試使用語法使兩條線相交(intersection cs: first line={}, second line={})。但是,以下範例的編譯並沒有達到我想要的效果:

%!TEX encoding = UTF-8 Unicode
%!TEX program = lualatex
\documentclass[11pt,a4paper,fleqn,pdftex]{report}
\usepackage[dvipsnames, table]{xcolor}
\usepackage[utf8]{luainputenc} 
\usepackage[latin,english]{babel}
\usepackage{tikz}
\usetikzlibrary{patterns}
\usetikzlibrary{shapes.geometric}

\begin{document}
    \begin{figure}[!h]
   \centering
   \begin{tikzpicture}
      \coordinate (S) at (-5 ,0);
      \coordinate (M'1) at (0,4.5);
      \coordinate (M2) at (0,3);
      \def\angleM{10}

      \draw[color=Red, thick] (M'1) -- (intersection cs: first line={(M'1)--++(90 - \angleM:-8)}, second line={(-5,-5) -- (5,5)}) circle (2pt) -- (S); % (S) -> (M'1)
      \draw[color=Red, thick] (M2) -- (intersection cs: first line={(M2) --++(90 - \angleM:-8)}, second line={(45:-4) -- (45:4)}) circle (2pt) -- (S); % (S) -> (M2)

      \draw (S) node[ellipse, fill=white, minimum height=3cm,minimum width=2mm,draw]{$(S)$};
      \begin{scope}[thick]
         \draw[densely dashed] (M'1) ++(1,0) -- ++(-2,0) node[left]{$M'_1$};
         \draw (M2) ++(1,0) -- ++(-2,0) node[left]{$M_2$};
      \end{scope}
      \fill[pattern=north east lines] (M'1) ++(1,0) rectangle ++(-2,0.2);
      \fill[pattern=north east lines] (M2) ++(1,0) rectangle ++(-2,0.2);
      \draw[very thick] (45:-2) -- (45:2);
   \end{tikzpicture}
\end{figure}
\end{document}

這段程式碼產生這樣的結果: 編譯結果

而我希望紅線與中心的黑線相交。我做錯了什麼嗎? PGF/TikZ 手冊沒有提供任何具有相對路徑的交集語法的範例。

答案1

不要在座標系中的線的規範中留下空格intersection:而不是

\draw[color=Red, thick] (M'1) -- (intersection cs: first line={(M'1)--++(90 - \angleM:-8)}, second line={(-5,-5) -- (5,5)}) circle (2pt) -- (S); % (S) -> (M'1)
\draw[color=Red, thick] (M2) -- (intersection cs: first line={(M2) --++(90 - \angleM:-8)}, second line={(45:-4) -- (45:4)}) circle (2pt) -- (S); % (S) -> (M2)

你應該使用

\draw[color=Red, thick] (M'1) -- (intersection cs: first line={(M'1)--++(90 - \angleM:-8)}, second line={(-5,-5)--(5,5)}) circle (2pt) -- (S); % (S) -> (M'1)
\draw[color=Red, thick] (M2) -- (intersection cs: first line={(M2) --++(90 - \angleM:-8)}, second line={(45:-4)--(45:4)}) circle (2pt) -- (S); % (S) -> (M2)

(為了使解釋更清楚,您second line={(-5,-5) -- (5,5)}在 的 兩側都有空格,--並且應該second line={(-5,-5)--(5,5)})沒有空格;另一個 的類似評論\draw

在此輸入影像描述

代碼:

%!TEX encoding = UTF-8 Unicode
%!TEX program = lualatex
\documentclass[11pt,a4paper,fleqn,pdftex]{report}
\usepackage[dvipsnames, table]{xcolor}
\usepackage[utf8]{luainputenc} 
\usepackage[latin,english]{babel}
\usepackage{tikz}
\usetikzlibrary{patterns,calc}
\usetikzlibrary{shapes.geometric}

\begin{document}
    \begin{figure}[!h]
   \centering
   \begin{tikzpicture}
      \coordinate (S) at (-5 ,0);
      \coordinate (M'1) at (0,4.5);
      \coordinate (M2) at (0,3);
      \def\angleM{10}

      \draw[color=Red, thick] (M'1) -- (intersection cs: first line={(M'1)--++(90 - \angleM:-8)}, second line={(-5,-5)--(5,5)}) circle (2pt) -- (S); % (S) -> (M'1)
      \draw[color=Red, thick] (M2) -- (intersection cs: first line={(M2) --++(90 - \angleM:-8)}, second line={(45:-4)--(45:4)}) circle (2pt) -- (S); % (S) -> (M2)

      \draw (S) node[ellipse, fill=white, minimum height=3cm,minimum width=2mm,draw]{$(S)$};
      \begin{scope}[thick]
         \draw[densely dashed] (M'1) ++(1,0) -- ++(-2,0) node[left]{$M'_1$};
         \draw (M2) ++(1,0) -- ++(-2,0) node[left]{$M_2$};
      \end{scope}
      \fill[pattern=north east lines] (M'1) ++(1,0) rectangle ++(-2,0.2);
      \fill[pattern=north east lines] (M2) ++(1,0) rectangle ++(-2,0.2);
      \draw[very thick] (45:-2) -- (45:2);
      \coordinate (L) at  ( $ (80 :-8) + (0,4.5) $ );
   \end{tikzpicture}
\end{figure}
\end{document}

事實上,您可以在之前留一個空格,--但在之後不可以!也許這可以被視為一個錯誤?

相關內容