给圆的某部分涂上阴影

给圆的某部分涂上阴影

圆圈

我该如何对上图中的 AB 段进行着色以便得到下图所示的结果? 在此处输入图片描述

这是我目前拥有的乳胶代码。

\documentclass[]{article}
\usepackage[margin=0.5in]{geometry}
\usepackage{pgfplots}
\usepackage{mathtools}
\usepackage{cancel}
\usepackage{pgfplots}
\usepackage{amsmath}
\newtheorem{theorem}{THEOREM}
\newtheorem{proof}{PROOF}
\usepackage{tikz}
\usepackage{amssymb}
\usetikzlibrary{patterns}
\usepackage{fancyheadings}
\usepackage{bigints}
\usepackage{color}
\usepackage{tcolorbox}
\usepackage{stackengine,graphicx,xcolor}
\usepackage{booktabs,array}
\usepackage{hyperref}
\usepackage{lscape}
\usetikzlibrary{shapes, positioning}
\usetikzlibrary{arrows}
\usetikzlibrary{trees}
\usepgfplotslibrary{fillbetween}
\begin{document}
\setlength{\parindent}{0cm}
%\pagecolor{blue!13}
\fancyhf{}
\fancyhead[C]{\thepage}
\voffset = 0.1cm
\pagestyle{fancy}
\definecolor{Elite}{RGB}{37,97,172}
\definecolor{web}{RGB}{56, 102, 166}
\setlength{\parindent}{0mm}
\setcounter{page}{1}
\begin{tikzpicture}
%
\draw [thick] (0,0) circle (2.5);
%
%\node[above] at (1.97,1.77) {A};
%\node[below] at (1.97,-1.77) {B};
%
\draw [fill=black] (0,0) circle (0.05);
\node[left] at (0,0) {O};
%
\draw[thick] (0,0) --+ (1.768,1.768);
\draw[thick] (0,0) --+ (1.768,-1.768);
%
\node[right] at (0.2,0) {$45^{\circ}$};
\draw[thick] (1.768,1.768)--+ (0,-3.536);
%
\node[above] at (0.3,0.9) {$2.5$ cm};
\node[below] at (0.3,-0.9) {$2.5$ cm};
%
\node[above] at (1.868,1.868) {$A$};
\node[below] at (1.868,-1.868) {$B$};
\end{tikzpicture}
\end{document}

非常感谢!

答案1

一种常见的方法是剪切该区域,然后在剪切后使用 \fill 命令:

PS:我使用 calc 库来计算位置(2.5\sqrt{2}/2)

\documentclass[]{article}
\usepackage[margin=0.5in]{geometry}
\usepackage{pgfplots}
\usepackage{mathtools}
\usepackage{cancel}
\usepackage{pgfplots}
\usepackage{amsmath}
\newtheorem{theorem}{THEOREM}
\newtheorem{proof}{PROOF}
\usepackage{tikz}
\usepackage{amssymb}
\usetikzlibrary{patterns}
\usepackage{fancyheadings}
\usepackage{bigints}
\usepackage{color}
\usepackage{tcolorbox}
\usepackage{stackengine,graphicx,xcolor}
\usepackage{booktabs,array}
\usepackage{hyperref}
\usepackage{lscape}
\usetikzlibrary{shapes, positioning,calc} %ADDED calc LIBRARY
\usetikzlibrary{arrows}
\usetikzlibrary{trees}
\usepgfplotslibrary{fillbetween}
\begin{document}
\setlength{\parindent}{0cm}
%\pagecolor{blue!13}
\fancyhf{}
\fancyhead[C]{\thepage}
\voffset = 0.1cm
\pagestyle{fancy}
\definecolor{Elite}{RGB}{37,97,172}
\definecolor{web}{RGB}{56, 102, 166}
\setlength{\parindent}{0mm}
\setcounter{page}{1}
\begin{tikzpicture}
%
  \draw [thick] (0,0) circle (2.5);
  \begin{scope}   %THESE 3 LINES WILL DO THE TRICK:
  \clip ({1.25*sqrt(2)},-2.5) rectangle (2.5,2.5);
  \fill[yellow] (0,0) circle (2.5);
  \end{scope}
  %
%\node[above] at (1.97,1.77) {A};
%\node[below] at (1.97,-1.77) {B};
%
\draw [fill=black] (0,0) circle (0.05);
\node[left] at (0,0) {O};
%
\draw[thick] (0,0) --+ (1.768,1.768);
\draw[thick] (0,0) --+ (1.768,-1.768);
%
\node[right] at (0.2,0) {$45^{\circ}$};
\draw[thick] (1.768,1.768)--+ (0,-3.536);
%
\node[above] at (0.3,0.9) {$2.5$ cm};
\node[below] at (0.3,-0.9) {$2.5$ cm};
%
\node[above] at (1.868,1.868) {$A$};
\node[below] at (1.868,-1.868) {$B$};
\end{tikzpicture}
\end{document}

输出:

在此处输入图片描述

答案2

只是为了完整性,没有剪辑,交叉点和对于该示例不必要的包。

\documentclass[]{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
%
\draw [thick] (0,0) circle (2.5);
%
%\node[above] at (1.97,1.77) {A};
%\node[below] at (1.97,-1.77) {B};
%
\draw [fill=black] (0,0) circle (0.05);
\node[left] at (0,0) {O};
%
\draw[thick] (0,0) --+ (1.768,1.768);
\draw[thick] (0,0) --+ (1.768,-1.768);
%
\node[right] at (0.2,0) {$45^{\circ}$};
\draw[thick] (1.768,1.768)--+ (0,-3.536);
%
\node[above] at (0.3,0.9) {$2.5$ cm};
\node[below] at (0.3,-0.9) {$2.5$ cm};
%
\node[above] at (1.868,1.868) {$A$};
\node[below] at (1.868,-1.868) {$B$};
\draw[-,fill=yellow] (1.768,1.768) arc [start angle=45,end angle=-45,radius=2.5]
-- cycle;

\end{tikzpicture}
\end{document}

在此处输入图片描述

答案3

另一种解决方案是使用圆形节点。这样我们就可以使用angular锚点,而不需要intersections库和先前计算的坐标值。

\documentclass[border=2mm,tikz]{standalone}
%\usepackage{tikz}
\usetikzlibrary{backgrounds}
\usepackage{siunitx}
\begin{document}
\begin{tikzpicture}
%
\node[circle, minimum size=5cm, draw, thick, label=45:$A$, label=-45:$B$] (c) {};

\begin{scope}[on background layer]
\fill[yellow] (c.45) arc[start angle=45, end angle=-45, radius=2.5cm]--cycle;
\end{scope}

\draw[fill] circle(1pt) node[left]{$O$} node[right]{\SI{45}{\degree}};

\draw[thick, line join=bevel] (c.center)--node[above left]{\SI{2.5}{\cm}} ([shift={(-135:.5\pgflinewidth)}]c.45)--([shift={(135:.5\pgflinewidth)}]c.-45)-- node[below left]{\SI{2.5}{\cm}} cycle;

\end{tikzpicture}
\end{document}

在此处输入图片描述

答案4

原谅另一个解决方案,但这里只是为了比较,是相同的图表元帖子-- 这被包裹在luamplib,因此编译lualatex或研究如何将其适配到普通的 MP,或者良好生产规范包裹。

在此处输入图片描述

\documentclass[border=5mm]{standalone}
\usepackage{luamplib, luatex85}
\begin{document}
\mplibtextextlabel{enable}
\begin{mplibcode}
beginfig(1);

    path C; C = fullcircle scaled 5cm;
    numeric a; a = 45;

    pair A, B;
    A = point  a * 8/360 of C;
    B = point -a * 8/360 of C;

    fill subpath (-a,a) * 8/360 of C -- cycle withcolor red + 3/4 green;

    draw origin -- B -- A -- cycle;
    draw C;

    dotlabel.lft("$O$", origin);
    dotlabel.urt("$A$", A);
    dotlabel.lrt("$B$", B);

    numeric r; 
    r = abs point 0 of C / cm;
    label.ulft(decimal r & "\thinspace cm", 1/2 A);
    label.llft(decimal r & "\thinspace cm", 1/2 B);

    draw subpath(-a,a) * 8/360 of fullcircle scaled 14;
    label("$" & decimal 2a & "^\circ$", 16 right);

endfig;
\end{mplibcode}
\end{document}

这里最有趣的是我试图让标签自动化,这样您就可以更改圆的直径和 A 的角度的值,并相应地调整标签。

请注意,MP 定义fullcircle路径有 8 个“点”,从 3 点开始编号为 0 到 7,因此您可以通过乘以将角度转换为点8/360

相关内容