和我的代码,我现在尝试在C_4
、D
和创建的三角形中添加背景阴影C_5
。我尝试使用pgfonlayer
,但它只会创建矩形阴影。这是我当前的代码:
\documentclass{article}
\usepackage{tikz, color, amsmath}
\usetikzlibrary{calc, arrows,backgrounds,positioning,fit}
\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 >=-0.5#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=-.10cm, 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.15cm, yshift=0cm]\ptext{C_6}}] at (4,1) {};
\draw [line] (C_1) -- (C_2) -- (C_3) -- (C_4) -- (C_5) -- (C_6) -- (C_1);
\node [dot={D}{blue},label={[xshift=0.15cm, yshift=-0.7cm]\ptext{D}}] at (.85,2.17) {};
\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:360+\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
}
\draw [ex line, very thick] (D) -- (C_1);
\node [dot={P}{red},label={[xshift=0.0cm, yshift=0.0cm]\ptext{P}}] at (3.85,4.87) {};
\draw[line, thick] (D) -- (P);
\begin{pgfonlayer}{background}
\node [fill=black!30,fit=(C_5) (D) (C_4)] {};
\end{pgfonlayer}
\end{tikzpicture}
\end{document}
并产生:
:
我怎样才能仅在三角形中设置阴影?谢谢。
编辑
C_4
在另一个问题中,我需要对由&处的延伸箭头包围的整个区域进行着色,该区域C_5
由一条弦(包含P
)和连接D
。我已将其更改为
\begin{pgfonlayer}{background}
\clip (C_5.center) -- (D.center) -- (C_4.center) -- (P) -- cycle;
\fill[yellow!70] (D) circle (4.7);
\end{pgfonlayer}
它产生一个四边形:
感谢您的帮助。
答案1
不需要添加node
带有 的定义fit
,只需使用 即可\fill
:
\begin{pgfonlayer}{background}
\fill[black!30] (C_5.center) -- (D.center) -- (C_4.center) -- (C_5.center);
\end{pgfonlayer}
\documentclass{article}
\usepackage{tikz, color, amsmath}
\usetikzlibrary{calc, arrows,backgrounds,positioning,fit}
\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 >=-0.5#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=-.10cm, 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.15cm, yshift=0cm]\ptext{C_6}}] at (4,1) {};
\draw [line] (C_1) -- (C_2) -- (C_3) -- (C_4) -- (C_5) -- (C_6) -- (C_1);
\node [dot={D}{blue},label={[xshift=0.15cm, yshift=-0.7cm]\ptext{D}}] at (.85,2.17) {};
\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:360+\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
}
\draw [ex line, very thick] (D) -- (C_1);
\node [dot={P}{red},label={[xshift=0.0cm, yshift=0.0cm]\ptext{P}}] at (3.85,4.87) {};
\draw[line, thick] (D) -- (P);
\begin{pgfonlayer}{background}
\fill[black!30] (C_5.center) -- (D.center) -- (C_4.center) -- (C_5.center);
\end{pgfonlayer}
\end{tikzpicture}
\end{document}
答案2
经过一些伪随机实验,我成功地做到了我想要的事情:
\begin{pgfonlayer}{background}
\fill[orange!30] (C_5.center) -- (D.center) -- (C_4.center);
\clip (3.7, 4) circle (1.56204);
\fill[yellow] (C_5.center)-- (C_4.center) -- (4.1, 7.0285) -- (7.1, 4.24489);
\end{pgfonlayer}