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}

事实上,你可以在 之前留一个空格,--但不能在 之后留一个空格!也许这可以算作一个错误?

相关内容