使用相对坐标填充圆弧

使用相对坐标填充圆弧

当我使用相对坐标时,填充圆弧时会遇到问题。如下图所示,填充从水平方向开始(对于上部 beta)。对于上部 alpha,我可以用一种丑陋的方法来“解决”这个问题,即不使用相对坐标,而是输入半径的近似值,这样就很难检测到它。

我在下面对 TikZ-Code 中存在问题的部分进行了评论。另外,顺便提一下,我对上部 beta 的“下方”定位感到不满。

在此处输入图片描述

\documentclass[12pt]{article}
\usepackage{tikz}
\begin{tikzpicture}[scale=1.5]

\filldraw[draw=green!50!black, fill=green!20] (0,0)--(.7,0) arc (0:30:.7cm);
% I want the line before drawing the arc to be .7cm long without having to use 5.36 as a coordinate
\filldraw[draw=green!50!black, fill=green!20] (30:{7*sqrt(3)/2})--(30:5.36) arc (210:240:.7cm);

\filldraw[draw=red!50!black, fill=red!20] (3.5,0)--(2.8,0) arc (180:60:.7cm);
\filldraw[draw=orange!50!black, fill=orange!20] (3.5,0)--(4.2,0) arc (0:60:.7cm);

\filldraw[draw=blue!50!black, fill=blue!20] (7,0)--(6.3,0) arc (180:120:.7cm);
% If I use a relative coordinate for the desired arc I can't fill it the way I want
\filldraw[draw=blue!50!black, fill=blue!20] (30:{7*sqrt(3)/2})++(-60:.7) arc (300:240:.7cm);

\node[label distance=.1 cm, label={180:A}] (A) at (0,0) {};
\node[label distance=.1 cm, label={0:B}] (B) at (7,0) {};
\node[label distance=.1 cm, label={90:C}] (C) at (30:{7*sqrt(3)/2}) {};
\draw (0,0)-- 
    node[midway, below]{r} 
    node[above, pos=.15, green!50!black]{$\alpha$}(3.5,0)
    node[above, pos=.95, red!50!black]{$\gamma$}-- 
    node[midway, below]{r}node[above, pos=.1, orange!50!black]{$\delta$}node[above, pos=.9,         blue!50!black]{$\beta$}(7,0)--
    % What am I doing wrong with the following label distance for beta? 1cm should be way off
    node[below, pos=.95, blue!50!black, label distance=1cm]{$\beta$}(30:{7*sqrt(3)/2})--
    node[below, pos=.07, green!50!black]{$\alpha$}(0,0);

\node[label distance=.1 cm, label={-90:M}] (D) at (3.5,0) {};
\draw (30:{7*sqrt(3)/2})--node[midway, below]{r} (3.5,0);
\draw[dashed, black!60] (7,0) arc (0:180:3.5cm);

\end{tikzpicture}
\end{document}

答案1

问题出在++不添加路径而只是移动坐标的情况下。如果只想修复代码,请确保圆弧一直延伸到拐角处。

\documentclass[12pt]{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[scale=1.5]

\filldraw[draw=green!50!black, fill=green!20] (0,0)--(.7,0) arc (0:30:.7cm);
% I want the line before drawing the arc to be .7cm long without having to use 5.36 as a coordinate
\filldraw[draw=green!50!black, fill=green!20] (30:{7*sqrt(3)/2})--(30:5.36) arc (210:240:.7cm);

\filldraw[draw=red!50!black, fill=red!20] (3.5,0)--(2.8,0) arc (180:60:.7cm);
\filldraw[draw=orange!50!black, fill=orange!20] (3.5,0)--(4.2,0) arc (0:60:.7cm);

\filldraw[draw=blue!50!black, fill=blue!20] (7,0)--(6.3,0) arc (180:120:.7cm);
% If I use a relative coordinate for the desired arc I can't fill it the way I want
\filldraw[draw=blue!50!black, fill=blue!20] (30:{7*sqrt(3)/2})++(-60:.7) arc (300:240:.7cm)
--(30:{7*sqrt(3)/2});

\node[label distance=.1 cm, label={180:A}] (A) at (0,0) {};
\node[label distance=.1 cm, label={0:B}] (B) at (7,0) {};
\node[label distance=.1 cm, label={90:C}] (C) at (30:{7*sqrt(3)/2}) {};
\draw (0,0)-- 
    node[midway, below]{r} 
    node[above, pos=.15, green!50!black]{$\alpha$}(3.5,0)
    node[above, pos=.95, red!50!black]{$\gamma$}-- 
    node[midway, below]{r}node[above, pos=.1,orange!50!black]{$\delta$}
    node[above, pos=.9,blue!50!black]{$\beta$}(7,0)--
    % What am I doing wrong with the following label distance for beta? 1cm should be way off
    node[below, pos=.95, blue!50!black, label distance=1cm]{$\beta$}(30:{7*sqrt(3)/2})--
    node[below, pos=.07, green!50!black]{$\alpha$}(0,0);

\node[label distance=.1 cm, label={-90:M}] (D) at (3.5,0) {};
\draw (30:{7*sqrt(3)/2})--node[midway, below]{r} (3.5,0);
\draw[dashed, black!60] (7,0) arc (0:180:3.5cm);

\end{tikzpicture}
\end{document}

在此处输入图片描述

我宁愿使用anglesquotes库(并使用数学模式A等)。您可以使用键设置角度的半径,这样可以更轻松地进行调整。您还可以使用样式进行填充,因为它是重复的(直到颜色)。

\documentclass[12pt]{article}
\usepackage{tikz}
\usetikzlibrary{angles,quotes}
\begin{document}
\begin{tikzpicture}[scale=1.5,label distance=.1cm,angle radius=1cm,
    pft/.style={draw=#1!50!black, fill=#1!20}]
  \path[draw] (0,0) coordinate[label={180:$A$}] (A) 
   -- (7,0) coordinate[label={0:$B$}] (B)  
   -- (30:{7*sqrt(3)/2}) coordinate[label={90:$C$}] (C)  
   -- cycle
   (C) -- (3.5,0) coordinate[label={-90:$M$}] (D)
   pic[pft=green,"$\alpha$"]{angle=A--C--D}
   pic[pft=green,"$\alpha$"]{angle=D--A--C}
   pic[pft=blue,"$\beta$"]{angle=D--C--B}
   pic[pft=blue,"$\beta$"]{angle=C--B--D}
   pic[pft=red,"$\gamma$"]{angle=C--D--A}
   pic[pft=orange,"$\delta$"]{angle=B--D--C}
   (A) edge["$r$"'] (D)
   (D) edge["$r$"'] (C)
   (D) edge["$r$"'] (B);
  \draw[dashed, black!60] (7,0) arc (0:180:3.5cm); 
\end{tikzpicture}
\end{document}

在此处输入图片描述

这就是为什么我在这里提倡自动解决方案:

\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{angles,quotes}
\tikzset{pft/.style={draw=#1!50!black, fill=#1!20}}
\begin{document}
\foreach \X in {40,50,...,140,130,120,...,50}
{\begin{tikzpicture}[scale=1.5,label distance=.1cm,angle radius=1cm,angle
eccentricity=0.75]
  \path[draw] (-3.5,0) coordinate[label={180:$A$}] (A) 
   -- (3.5,0) coordinate[label={0:$B$}] (B)  
   -- (\X:3.5) coordinate[label={90:$C$}] (C)  
   -- cycle
   (C) -- (0,0) coordinate[label={-90:$M$}] (D)
   pic[pft=green,"$\alpha$"]{angle=A--C--D}
   pic[pft=green,"$\alpha$"]{angle=D--A--C}
   pic[pft=blue,"$\beta$"]{angle=D--C--B}
   pic[pft=blue,"$\beta$"]{angle=C--B--D}
   pic[pft=red,"$\gamma$"]{angle=C--D--A}
   pic[pft=orange,"$\delta$"]{angle=B--D--C}
   (A) edge["$r$"'] (D)
   (D) edge["$r$"'] (C)
   (D) edge["$r$"'] (B);
  \draw[dashed, black!60] (3.5,0) arc (0:180:3.5cm); 
  \path (0,4); %<- only for animation
\end{tikzpicture}}
\end{document}

在此处输入图片描述

答案2

截屏

通过替换++--++它就可以起作用。

\filldraw[draw=blue!50!black, fill=blue!20] (30:{7*sqrt(3)/2})--++(-60:.7) arc (300:240:.7cm);%<--- replace ++ by --++

关于 beta 标签,您可以稍微修改代码,将标签放在稍微靠左和靠下的位置:

node[below,xshift=-5pt, pos=.93, blue!50!black, label distance=1cm]{$\beta$}(30:{7*sqrt(3)/2})

\documentclass[border=5mm,tikz]{standalone}
%\usepackage{tikz}
\begin{document}


\begin{tikzpicture}[scale=1.5]

\filldraw[draw=green!50!black, fill=green!20] (0,0)--(.7,0) arc (0:30:.7cm);
% I want the line before drawing the arc to be .7cm long without having to use 5.36 as a coordinate
\filldraw[draw=green!50!black, fill=green!20] (30:{7*sqrt(3)/2})--(30:5.36) arc (210:240:.7cm);

\filldraw[draw=red!50!black, fill=red!20] (3.5,0)--(2.8,0) arc (180:60:.7cm);
\filldraw[draw=orange!50!black, fill=orange!20] (3.5,0)--(4.2,0) arc (0:60:.7cm);

\filldraw[draw=blue!50!black, fill=blue!20] (7,0)--(6.3,0) arc (180:120:.7cm);
% If I use a relative coordinate for the desired arc I can't fill it the way I want
\filldraw[draw=blue!50!black, fill=blue!20] (30:{7*sqrt(3)/2})--++(-60:.7) arc (300:240:.7cm);%<--- replace ++ by --++

\node[label distance=.1 cm, label={180:A}] (A) at (0,0) {};
\node[label distance=.1 cm, label={0:B}] (B) at (7,0) {};
\node[label distance=.1 cm, label={90:C}] (C) at (30:{7*sqrt(3)/2}) {};
\draw (0,0)-- 
    node[midway, below]{r} 
    node[above, pos=.15, green!50!black]{$\alpha$}(3.5,0)
    node[above, pos=.95, red!50!black]{$\gamma$}-- 
    node[midway, below]{r}node[above, pos=.1, orange!50!black]{$\delta$}node[above, pos=.9,         blue!50!black]{$\beta$}(7,0)--
    % What am I doing wrong with the following label distance for beta? 1cm should be way off
    node[below,xshift=-5pt, pos=.93, blue!50!black, label distance=1cm]{$\beta$}(30:{7*sqrt(3)/2})(30:{7*sqrt(3)/2})--
    node[below, pos=.07, green!50!black]{$\alpha$}(0,0);

\node[label distance=.1 cm, label={-90:M}] (D) at (3.5,0) {};
\draw (30:{7*sqrt(3)/2})--node[midway, below]{r} (3.5,0);
\draw[dashed, black!60] (7,0) arc (0:180:3.5cm);

\end{tikzpicture}
\end{document}

答案3

angles图书馆可以使这项工作变得更容易。

在此处输入图片描述

\documentclass[12pt]{article}
\usepackage{tikz}
\usetikzlibrary{angles}

\begin{document}
\begin{tikzpicture}[scale=1.5, angle radius=1cm]

% coordinates 
\coordinate[label distance=.1 cm, label={180:A}] (A) at (0,0);
\coordinate[label distance=.1 cm, label={-90:M}] (M) at (3.5,0);
\coordinate[label distance=.1 cm, label={0:B}] (B) at (7,0);
\coordinate[label distance=.1 cm, label={90:C}] (C) at (30:{7*sqrt(3)/2});

% angles 
\pic [pic text=$\beta$, draw=blue!50!black, fill=blue!20] {angle=M--C--B};
\pic [pic text=$\beta$, draw=blue!50!black,fill=blue!20] {angle=C--B--M};
\pic [pic text=$\alpha$,draw=green!50!black,fill=green!20] {angle=M--A--C};
\pic [pic text=$\alpha$,draw=green!50!black,fill=green!20] {angle=A--C--M};
\pic [pic text=$\delta$,draw=green!50!orange,fill=orange!20] {angle=B--M--C};
\pic [pic text=$\gamma$,draw=red!50!black,fill=red!20] {angle=C--M--A};

% paths to connect the coordinates 
\draw (A) --  node[midway, below]{r} (M) --  node[midway, below]{r} (B)-- (C)-- (A)
  (M) --  node[midway, below]{r} (C);
\draw[dashed, black!60] (B) arc (0:180:3.5cm);

\end{tikzpicture}
\end{document}

相关内容