如何指定半彩色圆圈的位置和大小?

如何指定半彩色圆圈的位置和大小?

当尝试绘制半彩色圆圈时,我无法告诉脚本从哪里开始绘制,因为自定义命令使用极坐标形式的坐标开始绘制

    \documentclass{beamer}
\usepackage{tikz}
\begin{document}

\NewDocumentCommand{\statcirc}{ O{#2} m }{
    \begin{tikzpicture}
    \fill[#2] (0,0) circle (1.0ex); 
    \fill[#1] (0,0) -- (90:1.5ex) arc (90:270:1.5ex) -- cycle;
    \end{tikzpicture}
}

\begin{frame}
\frametitle{Frametitle}
    \begin{columns}
        \begin{column}{0.5\textwidth}
        En un diagrama de Venn se vería
                \begin{center}
            \begin{tikzpicture}[scale=0.7]
                \filldraw[fill=blue!20, draw=blue!60] (-2,0) circle (1.5cm);
                \filldraw[fill=red!20, draw=red!60] (2,0) circle (1.5cm);
                \statcirc[orange]{green}
                \node at (-2,1.8) {$D_{f}=R$};
                \node at (2,1.8) {$C_{f}=R_{f}$};
                \node at (0,1.2) {$f$};
                \node at (0,-2) {\textcolor{blue}{some text}};
                \node (x1) at (-1.5,0) {};
                \node (x2) at (-1.15,-0.4) {};
                \node (y1) at (1,0.5) {};
                \node (y3) at (1,-0.5) {};
                \draw[->] (x1) -- (y1);
                
            \end{tikzpicture}
            \end{center}

\begin{document}

我无法调整

   \fill[#1] (0,0) -- (90:1.5ex) arc (90:270:1.5ex) -- cycle;

因为如果我使用额外的参数(即圆心必须位于(2,0)),绘制就会重叠,被忽略或被破坏,如下图所示 在此处输入图片描述
当这个想法是圆圈的一半颜色是箭头的右边和更大

答案1

这是一个pic可以执行您的命令所要执行的操作,但可以放置在任何您喜欢的位置。这还可以避免嵌套tikzpicture环境。用法略有不同,它使用 pgf 键,控制半圆的颜色和半径。

\documentclass{beamer}
\usepackage{tikz}
\tikzset{pics/statcirc/.style={code={%
 \tikzset{statcirc/.cd,#1}
 \def\myvalue##1{\pgfkeysvalueof{/tikz/statcirc/##1}}
 \fill[color/.expanded=\myvalue{color 1}] (90:\myvalue{r1}) 
    arc[start angle=90,end angle=270,radius=\myvalue{r1}]; 
 \fill[color/.expanded=\myvalue{color 2}] (90:\myvalue{r2}) 
    arc[start angle=90,end angle=-90,radius=\myvalue{r2}]; 
 }},statcirc/.cd,color 1/.initial=orange,color 2/.initial=green,
    r1/.initial=1ex,r2/.initial=1.5ex}
\begin{document}

\NewDocumentCommand{\statcirc}{ O{#2} m }{
    \begin{tikzpicture}
    \fill[#2] (0,0) circle (1.0ex); 
    \fill[#1] (0,0) -- (90:1.5ex) arc (90:270:1.5ex) -- cycle;
    \end{tikzpicture}
}

\begin{frame}
\frametitle{Frametitle}
\begin{columns}[onlytextwidth,t]
  \begin{column}{0.5\textwidth}
   A Venn diagram
   \begin{center}
    \begin{tikzpicture}[scale=0.7]
        \filldraw[fill=blue!20, draw=blue!60] (-2,0) circle[radius=1.5cm];
        \filldraw[fill=red!20, draw=red!60] (2,0) circle[radius=1.5cm];
        \path (2,0) pic[transform shape]{statcirc={r1=1.5cm,r2=1cm}};
        \node at (-2,1.8) {$D_{f}=R$};
        \node at (2,1.8) {$C_{f}=R_{f}$};
        \node at (0,1.2) {$f$};
        \node[text=blue]at (0,-2) {some text};
        \node (x1) at (-1.5,0) {};
        \node (x2) at (-1.15,-0.4) {};
        \node (y1) at (1,0.5) {};
        \node (y3) at (1,-0.5) {};
        \draw[->] (x1) -- (y1);                
    \end{tikzpicture}
   \end{center}
  \end{column}
%
\end{columns}
\end{frame}
\end{document}

在此处输入图片描述

答案2

pic这是另一个答案中提出的替代方案。

在这种情况下,circle路径已被替换为圆形节点,在圆形节点上使用命令绘制半实心圆path picture

所有附加标签均采用相对定位方式放置,以节点名称为参考。

\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{positionIning}

\begin{document}
\begin{frame}
\frametitle{Frametitle}
Another Venn diagram

\begin{tikzpicture}
\node[circle, minimum size=2.1cm, fill=blue!20, draw=blue!60, label={$D_f=R$}] (left) {};
\node[circle, minimum size=2.1cm, fill=red!20, draw=red!60, label={$C_f=R_f$}, right=0.7cm of left,
path picture={\fill[red!60] (path picture bounding box.north) rectangle (path picture bounding box.south west); \fill[green] (right.center) --++(90:0.7) arc[start angle=90, end angle=-90, radius=0.7cm]--cycle;}] (right) {};
\draw[->] ([xshift=-7mm]left.east)--([xshift=3mm]right.160);
\path (left.north)--(right.north) node [midway, below] {$f$};
\path (left.south)--(right.south) node [midway, below, blue] {some text};
\end{tikzpicture}
\end{frame}
\end{document}

在此处输入图片描述

相关内容