圆圈和两条线之间的阴影

圆圈和两条线之间的阴影

我画出了单位圆和一些圆的切线。现在我想给圆所围的两条线之间的区域涂上阴影。这是我已经写好的文本。

\documentclass{article}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}[domain=0:4]
    \draw (0,0) circle (1cm);
    \draw ({-2.5},{sqrt(2)*(-sqrt(7)+sqrt(13))*(-2.5)-sqrt(13)+2*sqrt(7)}) -- ({1/sqrt(2)},{sqrt(7)});
    \draw (1.25, {-sqrt(2)*(sqrt(7)+sqrt(13))*(1.25)+sqrt(13)+2*sqrt(7)}) -- ({1/sqrt(2)},{sqrt(7)});                              
\end{tikzpicture}
\end{document}

我查看了其他与阴影有关的问题,但没有一个与圆形物体有关。也许我可以利用它可以被描述的事实sqrt(1-x^2)

答案1

以极高的计算成本,你可以计算出圆与线的交点,然后使用裁剪和even odd填充规则来生成

通过剪切、奇偶填充和计算进行着色

这使用intersections库、范围\clip和来even odd rule创建一个不神圣的组合。

\documentclass[border=10pt,multi,tikz]{standalone}
\usetikzlibrary{intersections}
\begin{document}
\begin{tikzpicture}[domain=0:4]
    \draw [name path=my circle] (0,0) coordinate (o) circle (1cm);
    \draw [name path=first line] ({-2.5},{sqrt(2)*(-sqrt(7)+sqrt(13))*(-2.5)-sqrt(13)+2*sqrt(7)}) -- ({1/sqrt(2)},{sqrt(7)}) coordinate (a);
    \draw [name path=second line] (a) -- (1.25, {-sqrt(2)*(sqrt(7)+sqrt(13))*(1.25)+sqrt(13)+2*sqrt(7)});
    \begin{scope}
      \clip [name intersections={of=first line and my circle, name=i}, name intersections={of=second line and my circle, name=j}] (i-1) -- (a) -- (j-1) -- cycle;
      \fill [blue!25, even odd rule, blend mode=multiply] (i-1) -- (a) -- (j-1) -- cycle (o) circle (1);
    \end{scope}
\end{tikzpicture}
\end{document}

一定一种更便宜的方法!

答案2

为了进行比较,这里有一个 Metapost 解决方案(我展示的是 ConTeXt 代码,但它可以与独立的 metapost 或 LaTeX + gmp 一起使用):

\starttext

\startMPpage[offset=2mm]
  z1 = (-2.5,sqrt(2)*(-sqrt(7)+sqrt(13))*(-2.5)-sqrt(13)+2*sqrt(7))*cm;
  z2 = (1/sqrt(2), sqrt(7))*cm;
  z3 = (1.25, -sqrt(2)*(sqrt(7)+sqrt(13))*(1.25)+sqrt(13)+2*sqrt(7))*cm;

  path p, q;
  path l[];

  p  := fullcircle scaled 2cm;
  l1 := z1 -- z2;
  l2 := z2 -- z3;

  pair t[];

  t1 := p intersectiontimes l1;
  t2 := p intersectiontimes l2;


  draw p;
  draw z1 -- z2;
  draw z2 -- z3; 

  q := subpath (ypart t1, 1) of l1 .. subpath (0, ypart t2) of l2 
      .. subpath(xpart t2, xpart t1) of p .. cycle;

  fill q withcolor 0.5[blue,white];


\stopMPpage
\stoptext

这使:

在此处输入图片描述

答案3

使用交叉口的闭式解决方案:

推导

\documentclass[border=2pt]{standalone}
\usepackage{mathtools}
\usepackage{tikz}

\begin{document}
\begin{minipage}{4in}
The circle is given by
\begin{equation}
x^2 + y^2 = r^2
\end{equation}
and the line by 
\begin{equation}
y = ax + b
\end{equation}
where
\begin{equation}
a = \frac{y_2-y_1}{x_2-x_1} \quad\textrm{and}\quad b = y_1 - ax_1 = y_2 - ax_2
\end{equation}
for any two points $(x_1,y_1)$ and $(x_2,y_2)$ on the line.

Substituting for $y$ using (2) into (1) we get
\begin{equation}
x^2 + a^2x^2 + 2abx + b^2 = r^2
\end{equation}
which has the solution
\begin{align}
x &= \frac{-ab}{a^2+1} \pm \frac{\sqrt{a^2 b^2 - (a^2+1)(b^2-r^2)}}{a^2+1}\notag\\
 &= \frac{-ab}{a^2+1} \pm \frac{\sqrt{a^2 r^2 - b^2 + r^2}}{a^2+1} \quad.
\end{align}
For a tangent point one can assume 
\begin{equation*}
a^2 r^2 - b^2 + r^2 = 0 \quad.
\end{equation*}

\begin{tikzpicture}
    \draw (0,0) coordinate (o) circle (1cm);
    \coordinate (a) at ({1/sqrt(2)},{sqrt(7)});
    \coordinate (b) at ({-2.5},{sqrt(2)*(-sqrt(7)+sqrt(13))*(-2.5)-sqrt(13)+2*sqrt(7)});
    \coordinate (c) at (1.25, {-sqrt(2)*(sqrt(7)+sqrt(13))*(1.25)+sqrt(13)+2*sqrt(7)});
    \draw (a) -- (b);
    \draw (a) -- (c);
    % find intersectons
    \pgfpointanchor{a}{center}\pgfgetlastxy{\xa}{\ya}%
    \pgfpointanchor{b}{center}\pgfgetlastxy{\xb}{\yb}%
    \pgfpointanchor{c}{center}\pgfgetlastxy{\xc}{\yc}%
    %find intersection of ab and circle.  Store back into (\xb,\yb)
    \pgfmathparse{(\ya-\yb)/(\xa-\xb)}\let\slope=\pgfmathresult
    \pgfmathparse{\ya-\slope*\xa}\let\yint=\pgfmathresult
    \pgfmathparse{-\slope*\yint/(\slope*\slope+1)}\let\xb=\pgfmathresult
    \pgfmathparse{\slope*\xb+\yint}\let\yb=\pgfmathresult
    \coordinate (bint) at (\xb pt,\yb pt);
    %find intersection of ac and circle.  Store back into (\xc,\yc)
    \pgfmathparse{(\ya-\yc)/(\xa-\xc)}\let\slope=\pgfmathresult
    \pgfmathparse{\ya-\slope*\xa}\let\yint=\pgfmathresult
    \pgfmathparse{-\slope*\yint/(\slope*\slope+1)}\let\xc=\pgfmathresult
    \pgfmathparse{\slope*\xc+\yint}\let\yc=\pgfmathresult
    \coordinate (cint) at (\xc pt,\yc pt);
    \begin{scope}
      \clip (bint) -- (a) -- (cint) -- cycle;
      \fill [blue!25, even odd rule, blend mode=multiply] (bint) -- (a) -- (cint) -- cycle (o) circle (1);
    \end{scope}
\end{tikzpicture}
\end{minipage}
\end{document}

相关内容