在 tikz 中标记反射角

在 tikz 中标记反射角

根据给出的第一个答案这里,我试图标记不同的角度。但是,我需要C_1 D C_6从另一个方向测量最后一个角度(反射角)我无法实现:

这是我的代码:

\documentclass{minimal}
\usepackage{tikz}
\usetikzlibrary{calc}

\usepackage{color, amsmath}
\newcommand\ptext[1]{\textcolor{purple}{$#1$}}

\begin{document}

\newcommand{\tikzAngleOfLine}{\tikz@AngleOfLine}
  \def\tikz@AngleOfLine(#1)(#2)#3{
  \pgfmathanglebetweenpoints{
    \pgfpointanchor{#1}{center}}{
    \pgfpointanchor{#2}{center}}
  \pgfmathsetmacro{#3}{\pgfmathresult}
  }

\begin{tikzpicture}[dot/.style 2 args={circle, color={#2},outer sep=0pt, inner sep=1.5pt, fill ,name=#1},
dot/.default={}{blue},
  ex line/.default = {1cm},
  ex line/.style={shorten >=-#1, ->, color=blue},
  line/.default=1cm,
  line/.style={}]

\node [dot={C_1}{green}, label={[xshift=-0.15cm, yshift=0.05cm]\ptext{C_1}}] at (0, 0) {};
\node [dot={C_2}{green}, label={[xshift=0.1cm, yshift=0.1cm]\ptext{C_2}}] at (-2.3,1) {};
\node [dot={C_3}{green}, label={[xshift=0cm, yshift=0cm]\ptext{C_3}}] at (-4,4.3) {};
\node [dot={C_4}{green}, label={[xshift=-.05cm, yshift=0.05cm]\ptext{C_4}}] at (2.5,5) {};
\node [dot={C_5}{green}, label={[xshift=0cm, yshift=0cm]\ptext{C_5}}] at (4.9,3) {};
\node [dot={C_6}{green}, label={[xshift=-0.1cm, yshift=0cm]\ptext{C_6}}] at (4,1) {};

\draw [line] (C_1) -- (C_2);
\draw [line] (C_2) -- (C_3);
\draw [line] (C_3) -- (C_4);
\draw [line] (C_4) -- (C_5);
\draw [line] (C_5) -- (C_6);
\draw [line] (C_6) -- (C_1);

\node [dot={D}{blue},label={[xshift=0.15cm, yshift=-0.7cm]\ptext{D}}] at (.85,2.17) {};
\draw [ex line, very thick] (D) -- (C_1);

\tikzAngleOfLine(D)(C_1){\AngleStart}

\foreach \num in {2, 3, 4, 5, 6}{    
\draw [ex line] (D) -- (C_\num);
\tikzAngleOfLine(D)(C_\num){\AngleEnd}

\draw[red,->] (D)+(\AngleStart:0.75+\num*0.15cm) arc (\AngleStart:\AngleEnd:0.75+\num*0.15cm);   
}

\end{tikzpicture}
\end{document}

怎么做?

答案1

您可以使用 if 条件或单独执行或使条件仅选择箭头大小等。这是一个通用的解决方案

\documentclass[tikz]{standalone}
\usetikzlibrary{calc}
\usepackage{amsmath}
\newcommand\ptext[1]{\textcolor{purple}{$#1$}}

\begin{document}

\newcommand{\tikzAngleOfLine}{\tikz@AngleOfLine}
  \def\tikz@AngleOfLine(#1)(#2)#3{
  \pgfmathanglebetweenpoints{
    \pgfpointanchor{#1}{center}}{
    \pgfpointanchor{#2}{center}}
  \pgfmathsetmacro{#3}{\pgfmathresult}
  }

\begin{tikzpicture}[dot/.style 2 args={circle, color={#2},outer sep=0pt, inner sep=1.5pt, fill ,name=#1},
dot/.default={}{blue},
  ex line/.default = {1cm},
  ex line/.style={shorten >=-#1, ->, color=blue},
  line/.default=1cm,
  line/.style={}]

\node [dot={C_1}{green}, label={[xshift=-0.15cm, yshift=0.05cm]\ptext{C_1}}] at (0, 0) {};
\node [dot={C_2}{green}, label={[xshift=0.1cm, yshift=0.1cm]\ptext{C_2}}] at (-2.3,1) {};
\node [dot={C_3}{green}, label={[xshift=0cm, yshift=0cm]\ptext{C_3}}] at (-4,4.3) {};
\node [dot={C_4}{green}, label={[xshift=-.05cm, yshift=0.05cm]\ptext{C_4}}] at (2.5,5) {};
\node [dot={C_5}{green}, label={[xshift=0cm, yshift=0cm]\ptext{C_5}}] at (4.9,3) {};
\node [dot={C_6}{green}, label={[xshift=-0.1cm, yshift=0cm]\ptext{C_6}}] at (4,1) {};

\draw [line] (C_1) -- (C_2);
\draw [line] (C_2) -- (C_3);
\draw [line] (C_3) -- (C_4);
\draw [line] (C_4) -- (C_5);
\draw [line] (C_5) -- (C_6);
\draw [line] (C_6) -- (C_1);

\node [dot={D}{blue},label={[xshift=0.15cm, yshift=-0.7cm]\ptext{D}}] at (.85,2.17) {};
\draw [ex line, very thick] (D) -- (C_1);

\tikzAngleOfLine(D)(C_1){\AngleStart}

\foreach \num in {2, 3, 4, 5, 6}{    
\draw [ex line] (D) -- (C_\num);
\tikzAngleOfLine(D)(C_\num){\AngleEnd}
\ifnum\num=6\relax
\draw[red,->] (D)+(\AngleEnd:0.75+\num*0.15cm) arc (\AngleEnd:\AngleStart:0.75+\num*0.15cm);   
\else
\draw[red,->] (D)+(\AngleStart:0.75+\num*0.15cm) arc (\AngleStart:\AngleEnd:0.75+\num*0.15cm);   
\fi
}

\end{tikzpicture}
\end{document}

在此处输入图片描述

答案2

正如我提到的,我只需将 percusse 解决方案中的这一行替换掉,就能找到解决方案

\draw[red,->] (D)+(\AngleEnd:0.75+\num*0.15cm) arc (\AngleEnd:\AngleStart:0.75+\num*0.15cm);   

\draw[red,<-] (D)+(\AngleEnd:0.75+\num*0.15cm) arc (\AngleEnd:360+\AngleStart:0.75+\num*0.15cm);   

, 这使:

相关内容