Tikz:在圆的边缘画一条线

Tikz:在圆的边缘画一条线

如果我想画一条线到圆的边缘,我可以简单地执行以下操作

\pgfmathsetmacro{\a}{2}
\draw (0, 0) circle (\a cm);
\draw[-latex] (0, 0) -- ({\a * cos(angle)}, {\a * sin(angle)});

其中角度就是我指定的角度。

所以我面临的问题是我想画两组 3 条线。一组对应较小的圆,另一组对应较大的圆。问题是圆的定义不像上面那样。此外,我想为每条线指定不同的角度。

有问题的圆圈的代码是

\documentclass[tikz,convert=false]{standalone}
\usetikzlibrary{through,calc,intersections}
\makeatletter
\tikzset{circle through extra radius/.code={% unorthodox addon for the through library
                                            % needs to be used after 'circle through'!
                                            % this can be avoided by slightly changing the source
  \tikz@addoption{%
    \pgfmathsetlengthmacro\pgf@tempa{\pgfkeysvalueof{/pgf/minimum width}+2*(#1)}%
    \pgfset{/pgf/minimum width/.expanded=\pgf@tempa}%
  }%
}}
\tikzset{
  special style/.code={%
    \if#1\tikz@nonactiveexlmark
      \pgfkeysalso{@special style}%
    \else
      \pgfkeysalso{style/.expanded=#1}%
    \fi
  },
  @special style/.style={draw=none,fill=none}
}
\makeatother 
\begin{document}
\begin{tikzpicture}[scale = .7,
    every label/.append style = {font = \small},
    dot/.style = {fill, outer sep = +0pt, inner sep = +0pt,
      shape = circle, draw = none, label = {#1}},
    dot/.default =,
    small dot/.style = {minimum size = 2.5pt, dot = {#1}},
    small dot/.default =,
    big dot/.style = {minimum size = 5pt, dot = {#1}},
    big dot/.default =
  ]
    \begin{scope}[rotate around ={-23.9625:(.75, -1)}]
      \begin{scope}
        \clip(-1, -4) rectangle (.5, 4);
        \draw [samples = 50, domain = -0.99:0.99, xshift = 1cm, red, thick]
        plot ({0.8 * (-1 - (\x)^2) / (1 - (\x)^2)},
        {1.83 * (-2) * (\x) / (1 - (\x)^2)});
      \end{scope}
      \node[scale = .75, small dot = {below: \(P_1\)}] (P1) at (3, 0) {};
      \node[scale = .75, small dot = {above, left = 3.5pt: \(P_2\)}] (P2) at
      (-1, 0) {};
      \node[scale = .75, small dot = {below, right = 5pt: \(F\)}] (F)
      at (.75, -1) {};
      \path[blue] (F) edge (P1) edge (P2) (P1) edge (P2);
      \path ($(P1)!.7!(P2)$) coordinate (Fm) node[small dot =
      {below = 10pt, right = 3pt: \(F_m^*\)}] {};
      \foreach \cPoint in {1, 2}
        \foreach \dDeltaRadius[count = \cRadius from 0] in
        {.0cm, .4cm, .8cm}
          \node[draw, red,
          name path global/.expanded = \cPoint:\cRadius] at
          (P\cPoint.center) (\cPoint:\cRadius) [circle through = (Fm),
          circle through extra radius = \dDeltaRadius] {};
      \foreach \cRadius in {1, 2} {
        \tikzset{name intersections = {of/.expanded = {1:\cRadius} and
            2:\cRadius, name/.expanded = n'-\cRadius}}
        \foreach \cSolution in {1, 2}
          \node[black, scale = .5, big dot =
          {right, below = 5pt: $\ifnum\cSolution = 1\expandafter\tilde F\else       
            F\fi^*_\cRadius$}]
          (n-\cRadius-\cSolution) at (n'-\cRadius-\cSolution){};
        }
    \end{scope}
  \end{tikzpicture}
\end{document}

在此处输入图片描述

因此,对于较大的圆圈,我希望从70350度开始按递减的顺序绘制线条P1,对于较小的圆圈,我希望从-225-180-145度开始按线长度递增的顺序绘制线条。

答案1

这将是一篇很长的回答(无论是长度还是细节)。
保持冷静,继续阅读。:)

如何获取圆/椭圆上的坐标:极坐标

虽然你可以使用以下方法访问圆上的坐标(或具有不同半径的椭圆)

({<x radius> * cos(<angle>)}, {<y radius> * sin(<angle>)})

TikZ 提供了更简单的输入极坐标,其隐式形式为:

  • (<angle>:<radius>)为圆上的坐标,
  • (<angle>:<x radius> and <y radius>)表示椭圆上的坐标。

如何获取圆心不在原点的圆/椭圆的坐标:移动/calc变换

当然,这样我们只能访问圆心位于原点的圆/椭圆上的坐标。shift当您想要访问其他极坐标时,此键会派上用场。序列(第一个没有库,第二个有库calc

\draw[shift=(P1)] (120:1cm) -- (50:.5cm) -- (40:.2cm);
\draw ($(P1)+(120:1cm)$) -- ($(P1)+(50:.5cm)$) -- ($(P1)+(40:.2cm)$);

将连接位于 周围圆上的坐标(P1)

如何访问(圆形)节点上的极坐标:节点的无限可能性

但我们真的知道确切的半径吗?不,我们也从来没有指定过它们。
through库使得无需指定半径即可通过点绘制圆。我们当然可以使用该calc库及其let … in …路径运算符来计算它,但我们不需要这样做。

除了(指南针)锚点(如north和 )之外,south east每个形状还包括(或应该包括)其边界的定义。
长话短说(对于不是circle或 的其他形状,情况则有所不同ellipse):圆形节点上的所有坐标都很容易访问:

(<node name>.<angle>)

我们示例中创建的圆圈是circle名为的节点:

  • 围绕(P1)
    • 1:0(额外半径 = .0cm
    • 1:1(额外半径 = .4cm
    • 1:2(额外半径 = .8cm
  • 围绕(P2)
    • 2:0(额外半径 = .0cm
    • 2:1(额外半径 = .4cm
    • 2:2(额外半径 = .8cm

(以这种方式或任何其他方式连接节点时,还需要考虑其他事项:outer xsep和的默认值outer ysep设置为,.5\pgflinewidth这意味着访问的锚点/角度位于路径边界的外部(线有宽度!)。这不适用于此处,因为它circle through还将两个外部分隔符都设置为零,使其更像典型的circle/ellipse路径运算符。)

提醒自己:要提前考虑!;)

但为什么

\draw (1:2.70) -- (1:1.35) -- (1:0.0);

给出这样的错误输出?

好吧,当 TikZ 解析坐标时,它会检查隐含某些坐标的各种文本序列。

在检查坐标系 ( cs:)、交点 ( intersections)、与其他坐标垂直和水平的坐标 (|--|) 之后,它首先检查极坐标 ( :),然后检查笛卡尔坐标 ( ,)。如果这些都不适用,则只有现在将坐标解释为节点规范。(因此,上面的坐标被解释为角度1和半径为2.7,1.35 and0.0` 的极坐标。)

我们可以通过以下方法解决这个问题:

  • 保护:免受解析器的攻击:

    \draw ({1:2}.70) -- ({1:1}.35) -- ({1:0}.0);
    
  • 使用节点坐标的显式形式:

    \draw (node cs: name=1:2,  angle=70) --
          (node cs: name=1:1, anchor=35) --
          (node cs: name=1:0, anchor=east);
    

    选项angleanchor可互换。

  • :从一开始就不使用(推荐)。
    将节点命名为从1-02-2可以更轻松地使用隐式形式:

    \draw (1-2.70) -- (1-1.35) -- (1-0.0);
    \draw (2-2.-225) -- (2-1.-180) -- (2-0.-145);
    

    我希望我正确理解了您想要连接的点。或者您正在寻找以下内容?

    \path (P1) edge (1-2.70) edge (1-1.35) edge (1-0.0)
          (P2) edge (2-2.-225) edge (2-1.-180) edge (2-0.-145);
    

    注意:我在上一个答案中曾使用:来使节点的名称与路径的名称相同。-在路径名称中使用 在某些回答阶段失败了,但:不知何故起作用了。现在,它又可以与 一起使用了-。这让我很困惑。

代码

\documentclass[tikz,convert=false]{standalone}
\usetikzlibrary{through,calc,intersections}
\makeatletter
\tikzset{circle through extra radius/.code={% unorthodox addon for the through library
                                            % needs to be used after 'circle through'!
                                            % this can be avoided by slightly changing the source
  \tikz@addoption{%
    \pgfmathsetlengthmacro\pgf@tempa{\pgfkeysvalueof{/pgf/minimum width}+2*(#1)}%
    \pgfset{/pgf/minimum width/.expanded=\pgf@tempa}%
  }%
}}
\makeatother 
\begin{document}
\begin{tikzpicture}[scale = .7,
    every label/.append style = {font = \small},
    dot/.style = {fill, outer sep = +0pt, inner sep = +0pt,
      shape = circle, draw = none, label = {#1}},
    dot/.default =,
    small dot/.style = {minimum size = 2.5pt, dot = {#1}},
    small dot/.default =,
    big dot/.style = {minimum size = 5pt, dot = {#1}},
    big dot/.default =
  ]
    \begin{scope}[rotate around ={-23.9625:(.75, -1)}]
      \begin{scope}
        \clip(-1, -4) rectangle (.5, 4);
        \draw [samples = 50, domain = -0.99:0.99, xshift = 1cm, red, thick]
        plot ({0.8 * (-1 - (\x)^2) / (1 - (\x)^2)},
        {1.83 * (-2) * (\x) / (1 - (\x)^2)});
      \end{scope}
      \node[scale = .75, small dot = {below: \(P_1\)}] (P1) at (3, 0) {};
      \node[scale = .75, small dot = {above, left = 3.5pt: \(P_2\)}] (P2) at
      (-1, 0) {};
      \node[scale = .75, small dot = {below, right = 5pt: \(F\)}] (F)
      at (.75, -1) {};
      \path[blue] (F) edge (P1) edge (P2) (P1) edge (P2);
      \path ($(P1)!.7!(P2)$) coordinate (Fm) node[small dot =
      {below = 10pt, right = 3pt: \(F_m^*\)}] {};
      \foreach \cPoint in {1, 2}
        \foreach \dDeltaRadius[count = \cRadius from 0] in
        {.0cm, .4cm, .8cm}
          \node[draw, red,
          name path global/.expanded = \cPoint-\cRadius] at
          (P\cPoint.center) (\cPoint-\cRadius) [circle through = (Fm),
          circle through extra radius = \dDeltaRadius] {};
      \foreach \cRadius in {1, 2} {
        \tikzset{name intersections = {of/.expanded = {1-\cRadius} and
            2-\cRadius, name/.expanded = n'-\cRadius}}
        \foreach \cSolution in {1, 2}
          \node[black, scale = .5, big dot =
          {right, below = 5pt: $\ifnum\cSolution = 1\relax\tilde F\else       
            F\fi^*_\cRadius$}]
          (n-\cRadius-\cSolution) at (n'-\cRadius-\cSolution){};
        }
    \end{scope}

    \draw (1-2.70) -- (1-1.35) -- (1-0.0);
    \draw (2-2.-225) -- (2-1.-180) -- (2-0.-145);
    % or
    \path (P1) edge (1-2.70) edge (1-1.35) edge (1-0.0)
          (P2) edge (2-2.-225) edge (2-1.-180) edge (2-0.-145);
  \end{tikzpicture}
\end{document}

输出

连接圆上的坐标

在此处输入图片描述

连接圆上的坐标与中心点

在此处输入图片描述

相关内容